Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a command button to import excel file 2

Status
Not open for further replies.

math20

MIS
Jul 7, 2005
71
CA
Hi

Can anyone help me with the code for a command button in access where I will get the same option as you would when you right click in the access database and then click on the import table option.
 
In your OnClick event coding do the following:
Code:
Private Sub cmdImport_Click()
    RunCommand acCmdImport
End Sub
This will open the Import dialog box just as if you click on the "Import Table" context menu option.

[shadeshappy] Cruising the Information Superhighway at the speed of light
[sub] (your mileage may vary)[/sub]
 
Thank you Wemeir. It works. But it gives me an error when I select teh excel file that I am trying to import. The error is subscript out of range. I get this error after I select teh worksheet I am trying to import then click next, and again when I try to store it in a table.

Any suggestion how to tackle this. So far I tried to timport the file by keeping the excel file open but that did not work. I am guessing it maybe the size, but the size I do not have any control over.

Once again thank you for your first code that works like a charm though.
 
If you try to manually import the Excel spreadsheet (i.e. right-click and choose Import) do you get the subscript error? Does the table already exist?

If neither is true, I'm not sure why you're getting the error. Try adding a DoEvents after the RunCommand and see if it clears up the problem.

[shadeshappy] Cruising the Information Superhighway at the speed of light
[sub] (your mileage may vary)[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top