S
scorpiorc
Hi, I'm trying to make a file dialog box which will allow the user to select
an Excel file to import into the table "Begin" in Access. I'm getting an
error at the point where the import process should begin. Can anyone help
with the code? Here is the code I have so far:
Option Compare Database
Option Explicit
Private Sub cmdFileDialog_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Don't allow the user to make multiple selections in the dialog box.
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Select File to Import"
' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "Excel Files", "*.XLS"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
DoCmd.TransferSpreadsheet acImport, 8, "Begin", varFile, True, ""
End Sub
an Excel file to import into the table "Begin" in Access. I'm getting an
error at the point where the import process should begin. Can anyone help
with the code? Here is the code I have so far:
Option Compare Database
Option Explicit
Private Sub cmdFileDialog_Click()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Don't allow the user to make multiple selections in the dialog box.
.AllowMultiSelect = False
' Set the title of the dialog box.
.Title = "Select File to Import"
' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "Excel Files", "*.XLS"
.Filters.Add "All Files", "*.*"
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
DoCmd.TransferSpreadsheet acImport, 8, "Begin", varFile, True, ""
End Sub