Hi, all.
I have a text file that I want to import into an existing table in my Access 2003 database (via Access 2007). I used the import wizard to import the data once and saved the steps as an import specification. I want to use that specification in some code to automate the process.
Here's my code:
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete From QBWLists"
DoCmd.TransferText acImportDelim, "TESTSPEC", "QBWLists", "C:\My Folder\MyFile.txt", False
DoCmd.SetWarnings True
When I run it, I get run-time error 3625, "The text file specification 'TESTSPEC' does not exist."
Hmm, I know that it does exist. So I tried a different method:
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete From QBWLists"
DoCmd.RunSavedImportExport "TESTSPEC"
DoCmd.SetWarnings True
And this runs perfectly. Hurray! Except for the fact that everything is hardcoded in with the RunSavedImportExport action, including the path and filename of the text file I'm importing. With the TransferText action, I can use the saved import specification while still supplying a new path and filename, which is what I want to do. Why? Because files could get moved around in the future, and then the hardcoded path in the import spec won't work anymore. I don't want to have to manually change my import spec if our file structure changes in the future.
Anyone have any suggestions? Note that I already tried creating a new database to make sure it isn't a corruption problem. Even in the new database file, the import spec won't run using the TransferText action.
Thanks,
Duluter
I have a text file that I want to import into an existing table in my Access 2003 database (via Access 2007). I used the import wizard to import the data once and saved the steps as an import specification. I want to use that specification in some code to automate the process.
Here's my code:
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete From QBWLists"
DoCmd.TransferText acImportDelim, "TESTSPEC", "QBWLists", "C:\My Folder\MyFile.txt", False
DoCmd.SetWarnings True
When I run it, I get run-time error 3625, "The text file specification 'TESTSPEC' does not exist."
Hmm, I know that it does exist. So I tried a different method:
DoCmd.SetWarnings False
DoCmd.RunSQL "Delete From QBWLists"
DoCmd.RunSavedImportExport "TESTSPEC"
DoCmd.SetWarnings True
And this runs perfectly. Hurray! Except for the fact that everything is hardcoded in with the RunSavedImportExport action, including the path and filename of the text file I'm importing. With the TransferText action, I can use the saved import specification while still supplying a new path and filename, which is what I want to do. Why? Because files could get moved around in the future, and then the hardcoded path in the import spec won't work anymore. I don't want to have to manually change my import spec if our file structure changes in the future.
Anyone have any suggestions? Note that I already tried creating a new database to make sure it isn't a corruption problem. Even in the new database file, the import spec won't run using the TransferText action.
Thanks,
Duluter