Hello,
I have some Access VBA code behind a button in a front end MS Access 2010 to select excel files and import them (as new data) into a linked SQL Server table (the back end).
Opening up the file selector dialog box is working well, but code throws a 2522 run time error 'Needs a file name argument' on the DoCmd.TransferSpreadsheet code:
Can anyone solve the run time error and my code?
Thanks
I have some Access VBA code behind a button in a front end MS Access 2010 to select excel files and import them (as new data) into a linked SQL Server table (the back end).
Opening up the file selector dialog box is working well, but code throws a 2522 run time error 'Needs a file name argument' on the DoCmd.TransferSpreadsheet code:
Code:
Private Sub cmdImportResults_Click()
Dim sExcelFile As String
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Allow user to make multiple selections in dialog box
.AllowMultiSelect = True
'Set the title of the dialog box
.Title = "Please select one or more files"
'Show the dialog box. If the .Show method returns True, the user picked at least one file.
If .Show = True Then
'Loop through each file selected and add it to the table
'' import the file to MSSQL linked table
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "[Database].Table_Results", sExcelFile, True
End If
End With
End Sub
Thanks
Last edited: