|
-
Nov 16th, 2011, 11:20 AM
#1
Thread Starter
Member
Access vba - import excel
Hi there,
I currently have a simple vba function which assists me with importing my excel spreadsheet into pre-defined tables in access. But I want to make it more professional.
This is my current code:
Code:
docmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "tblname", "myfilename", True
What I want to happen is once the import button has been clicked a windows folder/dialogue pops up for you to select the file you wish to import.
Is there a way to do this?
-
Nov 16th, 2011, 03:34 PM
#2
Re: Access vba - import excel
try like
vb Code:
myfilename = application.getopenfilename
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 16th, 2011, 03:42 PM
#3
Thread Starter
Member
Re: Access vba - import excel
Hi and thanks for the reply.
How and where would I put this code?
-
Nov 17th, 2011, 04:33 AM
#4
Re: Access vba - import excel
immediately before the docmd line
replace the "myfilename" string in the docmd, with the myfilename variable
you probably need some handling for if the user presses cancel in the dialog
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|