Importing fixed width text file with VBA (1 Viewer)

KirRoyale

Registered User.
Local time
Tomorrow, 07:42
Joined
Apr 22, 2013
Messages
61
Could someone please help? I am trying to attach a piece of code to a button on a form to import a fixed width text file with a saved import specification.

Private Sub ImportDataTest_Click()
DoCmd.TransferText acImportFixed, "Import-Call0CurrentCSV", "Call0CurrentTbl", "Call0CurrentFile"
DoCmd.Close
End Sub

I am getting a ‘runtime error 3625. The text file specification does not exist. You cannot, import, export or link using the specification’.
However, I have checked. The saved import of that name does exist and works when executed manually, the text file also exists.
Thank you in advance.
 

daievans

Registered User.
Local time
Today, 15:42
Joined
Apr 3, 2013
Messages
75
Saved Import is not the same as an Import Spec. The Import Spec is what you get when you've explored the Advanced button and save from that particular dialog. The import Spec is saved after you've completed defining the import fields - if you're SAved Import has your filename in it that is the default that access uses to save the overall process and to negate having to go through that manual process each time you import that particular file.
 

KirRoyale

Registered User.
Local time
Tomorrow, 07:42
Joined
Apr 22, 2013
Messages
61
Thank you for the response.
I went into the ‘advanced’ button and saved the spec. I then included that in my code:

Private Sub ImportDataTest_Click()
DoCmd.TransferText acImportFixed, "Call7CurrentFile Import Specification", "Call07urrentTbl", "Call7CurrentFile"
DoCmd.Close
End Sub

However, the 1st time I run the code (click the button) I get the same error message (31519).

Also, if I use the following code:

Private Sub ImportTextFiles_Click()
DoCmd.RunSavedImportExport "Import-Call0CurrentCSV"
End Sub

with the name of the saved import, that seems to work.

Are ‘DoCmd.TransferText’ and ‘DoCmd.RunSavedImportExport’ interchangeable in this instance?

Thank you.
 

daievans

Registered User.
Local time
Today, 15:42
Joined
Apr 3, 2013
Messages
75
Are ‘DoCmd.TransferText’ and ‘DoCmd.RunSavedImportExport’ interchangeable in this instance?


I don't know is the answer to your question as every file I import is differnet so I don't use the latter DoCmd - but I'm glad you got it to work!
 

Users who are viewing this thread

Top Bottom