JoeFletcher
asked on
How to prompt for an Excel spreadsheet to import into a table
I'm working in Access and playing with VBA. I want a user to click a button, have the file open dialog open, they select a spreadsheet, and then it imports into a table. The problem is the filename can be different every time. The table name will remain constant. I think it's something along the lines of below, but I don't know how to create a "variable?".
Private Sub ImportSpreadsheet_Click()
On Error GoTo Err_ImportSpreadsheet_Click
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Cleaning", "Choose your spreadsheet dialog", Yes
Exit_ImportSpreadsheet_Click:
Exit Sub
Err_ImportSpreadsheet_Click:
Resume Exit_ImportSpreadsheet_Click
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change the Sub to a Function and pass the filename in the function.
As a matter of fact, you can even pass a variable to a Sub, ergo the ()'s
ASKER
Thanks dude! That rocks!!!