zogpound said:
I'm trying to create a transfertext macro to import a delimited .txt file. I keep getting a "microsoft jet engine could not find XXXXfile. The file path name I believe is correct.
My situation is this: I receive several daily .txt file reports via e-mail. I want to automate importing these files into my database. My access skills are limited. Is the transfer text the best way to accomplish this task. Any suggestions which would save me from having to save and rename the file attachments each day.
Thanks, Eric
Hi Eric,
I have just een doing exactly what you are trying and indeed i was trying to use a Macro. Thanks to a chap from this forum i have got my DB working fantastically but i used an OnClick event procedure instead of a macro to do the work! and i take my data directly from a .CSV file and dont go anywhere near Excell.
Here is that code thanks to Anthony George:
Insert the following code into a Command button's on click event (i've used a button caled Command38)
The first row of the code deletes the old table Table1 (note! the first time you run this, an old table 1 must exist, any old
table will do even an empty table with just one field, so long as it is called Table1)
The second row of the code imports the file (My file is called MyExcelFile.csv, in a folder called aMacrotest, on the C
drive, obviously you can use any file,table,and folder names that you want so long as they match with the rest of the code)
The other 4 code rows rename the column headings.
Here is the Code:
Private Sub Command38_Click()
On Error GoTo Err_Command38_Click
DoCmd.DeleteObject acTable, "Table1"
DoCmd.TransferText acImportDelim, , "Table1", "C:\aMacroTest\MyExcelFile.csv", False
CurrentDb.TableDefs("Table1").Fields("F1").Name = "Make"
CurrentDb.TableDefs("Table1").Fields("F2").Name = "Product"
CurrentDb.TableDefs("Table1").Fields("F3").Name = "Packing"
CurrentDb.TableDefs("Table1").Fields("F4").Name = "Qty"
Exit_Command38_Click:
Exit Sub
Err_Command38_Click:
MsgBox Err.Description
Resume Exit_Command38_Click
End Sub
As you can see from this, it allows me to rename teh columns of the table after importing the data, This means that when i run a Query, my results make sense instead of being in columns named F1 F2 F3 etc etc
I hope that this helps you
Bev