Microsoft Access 2003 for PC Logo
Anonymous Posted on Sep 08, 2009

Unable to import text file to access table

Hey everyone. I have a challenge here that I should be able to figure out but I can't. I'm trying to use the VBA script below to import a text flat file into an existing access db table. Problem is, I can't seem to match the table fields to whats coming from the text file. Can anyone give me a hand?
Dim MyDB As DAO.Database, MyRec As DAO.Recordset
Dim MyList As String
Set MyDB = CurrentDb
Set MyRec = MyDB.OpenRecordset(''Select * From FlatFileImport'')

Dim filnam As String, s As String, MyLine As String, MyLocation As Long, ch As String
Dim once As Boolean

'filnam = ''C:Upload8507CTINC.txt''
filnam = Me![Text2]
Set MyRec = MyDB.OpenRecordset(''Select * From FlatFileImport'')
once = False
If Not IsNull(Me.Text2) Then filnam = Me.Text2
Open filnam For Binary As #1
MyLine = ''''
MyLocation = 0
Do While MyLocation < LOF(1)
ch = Input(99, #1)
If once Then
MyRec.AddNew
MyRec.Fields(1) = Mid(MyLine, 2, 2)
'MyRec.Fields(2) = Mid(MyLine, 3, 3)
MyRec.Fields(3) = Mid(MyLine, 6, 2)
MyRec.Fields(4) = Mid(MyLine, 8, 13)
'MyRec.Fields(5) = Mid(MyLine, 21, 5)
'MyRec.Fields(6) = Mid(MyLine, 26, 15)
'MyRec.Fields(7) = Mid(MyLine, 48, 6)
'MyRec.Fields(7) = '''' & Mid(MyLine, 48, 2) & ''/'' & Mid(MyLine, 50, 2) & ''/'' & Mid(MyLine, 52, 2) & ''''
'MyRec.Fields(8) = Mid(MyLine, 55, 5)
'MyRec.Fields(9) = Mid(MyLine, 62, 4)
'MyRec.Fields(10) = Mid(MyLine, 66, 5)
MyRec.Fields(11) = Mid(MyLine, 8, 8)
End If

once = True
MyLine = ''''
MyLine = MyLine & ch
MyLocation = Loc(1)
Loop

MsgBox '' File has been successfully imported! ''
Close #1 ' Close file.
MyRec.Close
Set MyRec = Nothing

1 Answer

Anonymous

Level 1:

An expert who has achieved level 1.

Problem Solver:

An expert who has answered 5 questions.

  • Contributor 1 Answer
  • Posted on Sep 09, 2009
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

Problem Solver:

An expert who has answered 5 questions.

Joined: Nov 06, 2007
Answers
1
Questions
3
Helped
263
Points
1

Hey everyone, I was able to fix my problem using the following:

filnam = Me![Text2]
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objText = objFile.OpenTextFile(filnam)
Set rs = CurrentDb.OpenRecordset("FlatFileImport")
once = False
If Not IsNull(Me.Text2) Then filnam = Me.Text2
Open filnam For Binary As #1
Do While Not objText.AtEndOfStream
strTextLine = objText.Readline
Data = Split(strTextLine, ",")
If once Then
rs.AddNew
rs.Fields(1) = Data(0) 'Site ID
rs.Fields(2) = Data(1) 'Client ID
rs.Fields(3) = Data(2) 'Client Name
rs.Fields(4) = Data(3) 'DDA Account
rs.Fields(5) = Data(4) 'Process Date
rs.Fields(6) = Data(5) 'Good Checks Singles
rs.Fields(7) = Data(6) 'Good Checks Stubs
rs.Fields(8) = Data(7) 'Good Checks Partial
rs.Fields(9) = Data(8) 'Good Stubs Partial
rs.Fields(10) = Data(9) 'Good Checks Multi
rs.Fields(11) = Data(10) 'Good Stubs Multi
rs.Fields(12) = Data(11) 'Check Only Checks
rs.Fields(13) = Data(12) 'Check Only Stubs
rs.Fields(14) = Data(13) 'Check And List Stubs
rs.Fields(15) = Data(14) 'Check And List Checks
rs.Fields(16) = Data(15) 'Suspense Checks
rs.Fields(17) = Data(16) 'Suspense Stubs
rs.Fields(18) = Data(17) 'Correspondence
rs.Fields(19) = Data(18) 'Envelopes
rs.Fields(20) = Data(19) 'Express Mail
rs.Fields(21) = Data(20) 'Lookup Stubs
rs.Fields(22) = Data(21) 'Online Lookups
rs.Fields(23) = Data(22) 'Stubs Only
rs.Fields(24) = Data(23) 'StopFile Hits
rs.Fields(25) = Data(24) 'SLC
rs.Fields(26) = Data(25) 'SL2
rs.Fields(27) = Data(26) 'MICR Scanline
rs.Fields(28) = Data(27) 'KeyStrokes Correspondence
rs.Fields(29) = Data(28) 'Keystrokes SLC
rs.Fields(30) = Data(29) 'Keystrokes SL2
rs.Fields(39) = Data(38) 'Exception Queue
rs.Fields(40) = Data(39) 'COA Queue


'IMAGE ARCHIVE ITEMS
rs.Fields(41) = Data(40) 'Image Archive Reports
rs.Fields(42) = Data(41) 'Image Archive Storage

'BATCHES PROCESSED
rs.Fields(43) = Data(42) 'Batches Processed

'ARC ITEMS
rs.Fields(44) = Data(43) 'Low Speed ARC Attempts
rs.Fields(45) = Data(44) 'High Speed ARC Attempts
rs.Fields(46) = Data(45) 'Low Speed ARC Converted
rs.Fields(47) = Data(46) 'High Speed ARC Converted

'ICL ITEMS
rs.Fields(48) = Data(47) 'ICL Attempts
rs.Fields(49) = Data(48) 'ICL Converted
rs.Fields(50) = Data(49) 'ICL Non-Conforming images

'RETURN ITEMS
rs.Fields(51) = Data(50) 'Auto Returns
rs.Fields(52) = Data(51) 'Returned Items

'POSITIVE POST (CDM) ITEMS
rs.Fields(53) = Data(52) 'Positive Post Checks
rs.Fields(54) = Data(53) 'Positive Post Stubs

'REMOTE PAYMENT CAPTURE ITEMS
rs.Fields(55) = Data(54) 'Remote Payment Single Checks
rs.Fields(56) = Data(55) 'Remote Payment Single Stubs
rs.Fields(57) = Data(56) 'Remote Payment Multi Checks
rs.Fields(58) = Data(57) 'Remote Payment Multi Stubs
rs.Fields(59) = Data(58) 'Remote Payment Check Only Checks
rs.Fields(60) = Data(59) 'Remote Payment Check Only Stubs
rs.Fields(61) = Data(60) 'Remote Payment Check & List Checks
rs.Fields(62) = Data(61) 'Remote Payment Check & List Stubs

'DOLLAR DEPOSTIED & PP CORRO REJECT ITEMS
rs.Fields(71) = Data(70) 'Dollars Deposited
rs.Fields(72) = Data(71) 'PP Corro Rejects



rs.Update
End If

once = True
MyLine = ""
MyLine = MyLine & ch
MyLocation = Loc(1)
Loop
MsgBox " File has been successfully imported! "
Close #1 ' Close file.
rs.Close
'close and erase the file from memory
objText.Close
Set objText = Nothing
Set rs = Nothing

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1helpful
1answer

Want to import email addresses into MS Outlook

Hey! follow the steps to get your job done


You can import address book contacts from other Microsoft Windows® Address Book files (.wab), as well as from Netscape Communicator, Microsoft Exchange Personal Address Book, or any text (.csv) file.
For Windows Address Book 1.
On the File menu, point to Import, and then click Address Book.
2.
Select the address book or file type you want to import, and then click Open.

For All Other Address Book Formats 1.
On the File menu, point to Import, and then click Other Address Book.
2.
Click the address book or file type you want to import, and then click Open.

If your address book is not listed, you can export it to either a text (.csv) file or a Lightweight Directory Access Protocol (LDAP) or Lightweight Directory Interchange Format (LDIF) file, and then import it using that file type.



Good luck :-)
15helpful
7answers

Undelete records from access table

ou can try to use third party Access recovery utility to restore your lost and damaged data from .mdb files. For more details about this software:-
Access File Recovery
0helpful
1answer

Write into excel format

Your code does not save in access format it just makes a copy of existing file. You need to open table by table and export data using csv format.
It can be done using access OLE to export, or
write some VB code to access the database tables via ODBC and save row data to csv file
0helpful
2answers

Steps in saving file in excel to database

severals solution :
- save file as text separated by comma and use sqloader from oracle
- use function in excel to concatenate insert order : "insert into TABLE_NAME (field1,...,fieldn) values (A1,B1,...,??n);". Save file as text with sql extension. Connect against roacle db and execute file previously saved.
- use ODBC from MicroSoft
0helpful
1answer

Code for find the Ms access database size using visual basic

The way to get the database size is to point to the directory that the database is do a DIR statement with an output to a file as in DIR payroll.mdb>dbsize.txt and then read from the text file, the first field of the second line being the name (which you really don't need) then the size value of the database.

To import the text files using VB 8 use

'Imports System.Data.OleDb Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\path\filename.mdb") Dim cmd As New OleDbCommand("SELECT * INTO [import] FROM [Text;Database=d:\path;Hdr=No].[dbsize.txt]", conn) conn.Open() cmd.ExecuteNonQuery() conn.Close()
0helpful
1answer

Import Database - No tables

Your table may be open in another application. Try closing the database or file, and then try to the import process again.
0helpful
1answer

DOS Programme to txt file

Assuming that you are not able to export the data from the
original point of sale application, which is obviously the
best choice...

1)
Try to open the file(s) with Microsoft Excel (make sure that all of Excel's input conversion filters have been installed and enabled).

Most database files are organized as a set of (nested)
two dimensional data tables, which can be individually
imported into Excel as spread sheets.

Excel is very good at detecting and converting database tables.
Other spread sheets such as Lotus 123, or Quatro pro may also
be able to do this.

2) Microsoft Access may also be capable of importing
and converting the entire database.

3) Heavy duty data-base modeling suites, such as ER-Win
by Computer Associates (CA) may also be able to import
and export the database.

4) If the files are in the open *.dbf format, then I have the binary
file specifications, which can be used to decipher the files.

5) The files may also be simple tables, which are TAB, SPACE,
or COMMA (etc.) delimited, and you should be able to recover
these with a simple notepad editor or uuedit.

6) Most DOS programs (not all) can also be run under Windows
XP, using the command prompt:

START ==> All programs ==> Accessories ==>
Command Prompt.

========================================
Most importantly, we need to know the name of the application
that created the files, or see a sample of the file, to give you
further advice.

Martin
0helpful
1answer

Dreamweaver CS3

Import Microsoft Office documents (Windows only) You can insert the full contents of a Microsoft Word or Excel document in a new or existing web page. When you import a Word or Excel document, Dreamweaver receives the converted HTML and inserts it into your web page. The file’s size, after Dreamweaver receives the converted HTML, must be less than 300K.
Instead of importing the entire contents of a file, you can also paste portions of a Word document and preserve the formatting.
Note: If you use Microsoft Office 97, you cannot import the contents of a Word or Excel document; you must insert a link to the document.
  1. Open the web page into which you want to insert the Word or Excel document.
  2. In Design view, do one of the following to select the file:
    • Drag the file from its current location to the page where you want the content to appear.
    • Select File > Import > Word Document or File > Import > Excel Document.
  3. In the Insert Document dialog box, browse to the file you want to add, select any of the formatting options from the Formatting pop-up menu at the bottom of the dialog box, and then click Open. Text Only Inserts unformatted text. If the original text is formatted, all formatting will be removed.
    Text With Structure Inserts text that retains structure, but does not retain basic formatting. For example, you can paste text and retain the structure of paragraphs, lists, and tables, without retaining bold, italics, and other formatting.
    Text With Structure Plus Basic Formatting Inserts both structured and simple HTML-formatted text (e.g., paragraphs and tables, as well as text formatted with the b, i, u, strong, em, hr, abbr, or acronym tag).
    Text With Structure Plus Full Formatting Inserts text that retains all structure, HTML formatting, and CSS styles.
    Clean Up Word Paragraph Spacing Eliminates extra space between paragraphs when you paste your text if you selected Text With Structure or Basic Formatting. The contents of the Word or Excel document appear in your page.
Source: Dreamweaver CS3 Help
0helpful
1answer

Restriction on import of forms and tables in msaccess

I could not understand the 1st question clearly.
as for the second question you can download microsoft viewers for any office product at their site. they can view files only.
Not finding what you are looking for?

273 views

Ask a Question

Usually answered in minutes!

Top Microsoft Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

k24674

Level 3 Expert

8093 Answers

Brad Brown

Level 3 Expert

19187 Answers

Are you a Microsoft Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...