Share via

Get external data using using DoCmd (VBA)

Anonymous
2013-09-22T12:49:13+00:00

I would like to create a customized Import procedure for a text file that needs to be imported into a table using VBA (NOT MACRO)

  1. What is the DoCmd command for running a saved import?
  2. Is there a way to use variables for file path and File name in the code?

Thank you.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-09-22T13:01:14+00:00

The syntax for running a saved import is

DoCmd.RunSavedImportExport "NameOfSavedImport"

This will use the path and file name stored with the saved import; you cannot specify those.

Alternatively, you can use DoCmd.TransferText. This will let you specify the path and file name:

DoCmd.TransferText TransferType:=acImportDelim, SpecificationName:="MySpecification", _

    TableName:="MyTable", FileName:="C:\Data\MyTextFile.txt", HasFieldNames:=True

Instead of the literal quoted strings in this instruction, you can use variables or expressions.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful