Import Specifications

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi! I'm pretty new at VBA coding ... so here's what I'm trying to do:

I have created an import specification for a .csv file. I'd like to allow
the user to select the file they want imported and then to automatically
perform the import to the Access table. Also, is it possible to clear the
table of the prior data before importing?

Thanks!

Cindy
 
Cindy,

Here is some code that was provided by Douglas Steel a while back. Perhaps
it will help you to have the user locate the file to import.

Dim strFilter As String
Dim strInputFileName as string

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
strInputFileName contains the full path to whatever file was selected.

In Doug's code he is looking for Excel files. You can modify that part of
the code to look for only .csv files if that is what you need. Something like:
strFilter = ahtAddFilterItem(strFilter, "Comma Seperated Value Files
(*.csv)", "*.csv")

As for emptying the table first, use a Delete type sql statement like:

dim strSql as String

strSql = "DELETE * FROM YourTableName;"
Currentdb.Execute strSql
 
Thanks, "Mr B". I can't get the locate file part to work. But you did give
me some ideas ... and the SQL command was perfect for clearing the file.
Thanks for your help!

Cindy
 
Back
Top