Link to home
Start Free TrialLog in
Avatar of JoeFletcher
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of JoeFletcher
JoeFletcher

ASKER

Thanks dude!  That rocks!!!