Importing Data from Excel: Please help.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi,I need help with VBA to import Data from Excel into Acccess. I have excel templete where data is being field out and then different users from thier own end [fill out this required data and append it to access table.]

Now what i want to do it, to have a button in a form and then when click on i want dailog box to pop up and let users select the templete excel workbook and then when selected i want the data from sheet1 [particular] range to be imported to this access table1...

Is this possible?
Please make it work for me...


Thanks in advance everyone!


Pedie:)
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Pedie

Please read the posting guidelines <a href="http://www.mrexcel.com/forum/showthread.php?t=127080">here</a> if you haven't already and please pay particular attention to points 5,6,7 and 8. As you have already realised people on this forum are more than willing to help but there is normally an expectation that you will make some effort to solve the problem yourself. I am not trying to be mean but with 3000+ posts you should be getting this by now.

For this particular question you first need to work out how to display a File Open dialog box in Access. A quick Google search of this site found <a href="http://www.mrexcel.com/forum/showthread.php?t=82469">this post</a>.

You then need to import the chosen file. If it's just a specific range then you should be able to create an import specification and then use Docmd.TransferSpreadsheet to get the data in.

Please have a go at trying to do this yourself - if/when you get stuck then please post back with the problems you're having :-)

DK
 
Upvote 0
Hi Pedie,

In your database have you looked at using the DoCmd.TransferSpreadsheet command?

You can supliment the workbook name with the Excel Dialogue box option.

Here is sample code to open the dialog box

Sub cmdFileDialog_Click()

' Requires reference to Microsoft Office 11.0 Object Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant


' Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

With fDialog

' Allow user to make multiple selections in dialog box
.AllowMultiSelect = True

' Set the title of the dialog box.
.Title = "Please select one or more files"

' Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Excel Workbooks", "*.XLS"

.Filters.Add "All Files", "*.*"

' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then

'You can add the DoCmd Transfer here
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
 
Upvote 0
Thanks Trevor, thanks DK for the link and for reminding me the forum regulations...:) the thing is that 'm really new to access and just dont know what to look for sometime...even if i look dont know how does it work....

From your suggestions i tried the following code which errored...

External table is not the expected format - 3274 runtime error..

went though this link but i dont think i can make this work myself...
:(

Code:
[/FONT]
[FONT=Courier New]DoCmd.TransferSpreadsheet acImport, 3, "MyTable", "C:\Users\Pediez\Desktop\Book1.xlsm", True, "A2:a10"[/FONT]
[FONT=Courier New]
 
Upvote 0
Trevor, from the code you've provided how can i get the selected file name?:)

Thanks again.
 
Upvote 0
Sorry Pedie,

I have been away from the PC most of today, I hope you have a working solution.:)

Enjoy the weekend....
 
Upvote 0
Hi Trevor, that okay and yes the problem is solved now....

You have a great weekend too!:)
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top