Can Someone Help Me Write

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

Guest

Want code to execute:

File, Get External Data, Import, H:\Inventor\ (So I want this to open dialog
box in this directory so user can pick file to Import), Files of Type -
Microsoft Excel (Again, would like this to be the default)

Thanks so much!
Tony
 
First, you will need the code from this site. It is used to present the
Open/Save file dialog box.
http://www.mvps.org/access/api/api0001.htm
Once you have used that to get the file name, you will use the
TransferSpreadsheet to to the import.

Here is an example from one of my apps:

Dim varGetFileName As Variant

'See if data for the month and year already exits
On Error GoTo LoadNonVAII_Error

'Get the file to import
Do While True
varGetFileName = ahtCommonFileOpenSave(ahtOFN_OVERWRITEPROMPT, , _
"Excel Spreadsheets (*.xls) *.xls", , _
"xls", , "Load Non Vought Invoice Data", , True)
If varGetFileName = "" Then
If MsgBox("Cancel Import?", vbQuestion + vbYesNo, "Load Non
Vought Data") _
= vbYes Then
Exit Function
End If
Else
Exit Do
End If
Loop

'Delete the old data
CurrentDb.Execute ("DELETE * FROM NonVAII"), dbFailOnError
'Import the New Data
DoCmd.TransferSpreadsheet acImport, 8, "NonVAII", _
varGetFileName, True

MsgBox "Import Complete", vbOKOnly, "Load Non Vought Data"
 
Back
Top