Selecting a File to Import From at Runtime of an Event Procedure

G

Guest

I have a dialog box that needs to import data from an excel or csv file, run
an append query to another table based on it, then remove that data.
However, in order for it to be truly useful to other people besides me, it
needs to let them select the file to import from at runtime so they don't
accidentally run the append query twice with the same data. However, even
though both the TransferSpreadsheet and TransferText methods say that File
Name is an optional argument, the code will not run unless the file name is
specified in the DoCmd line. I know when I use the OutputTo method, leaving
the filename blank brings up the file open dialog and lets you specify the
file at runtime. Is there an equivalent command to do the same thing when
importing?
 
G

Guest

Will this also work for csv files? The broadcast fax/e-mail program returns
the results files as csv.
 
G

Guest

It works for any type of file. If you examine the example, you will find you
can define which files it will show. Here is an example I use where I am
importing a csv file. Notice the variable strFilter

'Get the file to import
'Flags Hides the Read Only Check and Only allow existing files
lngFlags = ahtOFN_HIDEREADONLY Or ahtOFN_FILEMUSTEXIST
'Set filter to show only csv spreadsheets
strfilter = ahtAddFilterItem(strfilter, "Text Files (*.csv)")
'Set the Default File Name
strFileName = "VoughtBillCurrentMonth.csv"
'Set the Default Path
strDefaultDir = "\\rsltx1-bm01\FTPData$"
'Call the Open File Dialog
Do While True
varGetFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
Filter:=strfilter, _
FileName:=strFileName, _
InitialDir:=strDefaultDir, _
Flags:=lngFlags, _
DialogTitle:="Import BillCurrMonth3345")
Me.Repaint
If varGetFileName = "" Then 'User clicked Cancel
If MsgBox("Cancel Import?", vbQuestion + vbYesNo, "Import
BillCurrMonth3345") _
= vbYes Then
blnOkGo = False
Exit Do
End If
Else
blnOkGo = True
Exit Do
End If
Loop
 

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