Home » excel » excel – Transfer Spreadsheet to Access Database with VBA

excel – Transfer Spreadsheet to Access Database with VBA

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a browse button and pick and place the file name and path in textbox5. I need to use the same value in my file name but it does not work. It throws:

Run Time Error 2522- The action or method requires a File Name argument

Private Sub Command10_Click()
  Dim dbs As DAO.Database
  Dim td As DAO.TableDef
  Dim fileName As String

'set current database
 Set dbs = CurrentDb

 Me.Text5 = fileName

DoCmd.TransferSpreadsheet acImport, , "tblS3DimportTemp", fileName, True
 MsgBox "Data Uploaded!"

End Sub
How to&Answers:

Instead of: Me.Text5 = fileName

write:
fileName = Me.Text5

In many programming languages the left variable gets the value of the right one.