Using Import Specifications for an import through VBA

F

Frank M

I have a monthly update to make on an Access database (2000 format) that
involves the execution of several imports queries.
I have all the actions to be done in a table in Access. Now I want to
automate the whole job through a program. As far as I can see running the
queries can be done through the DoCmd object, the RunSQL method (or perhaps
better through ADO and ADOX to get the query contents).
However, I can't see how I would perform the imports using the Import
specifications that I have saved in the database.
Besides giving the Import Spec name I would also have to give the name of
the table to be imported too. So my question is:

How can I start an import with a given Import Spec (by name) to a named table?

I have found an Application.DoCmd object with a RunCommand method that I can
use with the parameter acCmdImport. But my guess is that this will just open
the Import dialog window from which I would have to proceed manually. I don't
see anywhere to specificy the import spec name or input table name in the
call of the method.

Hope someone can help.


Best regards,

Frank M.
 
A

Allen Browne

Try TransferText, e.g.:

DoCmd.TransferText acImportDelim, "MySpec", "MyTable", "C:\MyFile.txt"
 
F

Frank M

Hrm.. I guess the DoCmd.RunCommand with acCmdImport was not the right way. I
found the DoCmd.TransferText method which will do the job nicely. Here you
can specify Import spec name, input table name, etc.


Frank M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top