Get filename from import path

WineSnob

Not Bright but TENACIOUS
Local time
Today, 16:24
Joined
Aug 9, 2010
Messages
211
I am importing a .txt file into a table "MasterAging". I would like to add the filename to another table called "Filename". What would the code be to write the filename of the file being imported to the table "Filename"? Would the code be place just after the this:
DoCmd.TransferText acImportDelim, "AgingImport", "MasterAging", sPath
 
Thanks for the response. I have been beating on it for a few hours now and finally got what I wanted. Here is what I used.

Set rs = db.OpenRecordset("filename", dbOpenDynaset)
rs.AddNew
rs.Fields("Filename") = Mid(sPath, intlen + 2, Len(sPath) - intlen - 5)
rs.Update
 
An alternative way is:


rs("FieldName") = Mid(sPath, InstrRev(1, sPath, "\") + 1)
 
I thought I would give that a try and I get a Type Mismatch error.
 
Sorry, I had remembered the InstrRev syntax wrong. It should be:

rs("FieldName") = Mid(sPath, InstrRev(sPath, "\") + 1)
 
That worked ! :D It also added the .txt better solution.
I was looking at your Code Store on your site. You should call it COOL CODE STORE. I am going to use it and continue to add to it. I am not really a programmer but can "borrow and revise to fit my applications". This will help alot...... THANKS :D:D:D
 

Users who are viewing this thread

Back
Top Bottom