Forum Discussion
Sean Sodha
Apr 25, 2018Copper Contributor
Excel Data Exported to Microsoft Access --> Object Required
Hi everyone. Within Excel, I am trying to create a table in Microsoft Access, and then export a range of data in Excel into that Access table. I am successful in creating a table in Microsoft Access....
Sean Sodha
Apr 30, 2018Copper Contributor
Hmm it gives me an "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another". Any advice?
Matt Mickle
Apr 30, 2018Bronze Contributor
Try this VBA code block instead.... You will need to add the reference to the Access Object Library as mentioned in the code comments. In addition if the file you are running the code out of is not "C:\Users\jt\Desktop\Inventory Policy Analysis.xlsm" then you will need to update the FileName Parameter :
Option Explicit
Sub AccImport()
Dim acc As New Access.Application
Dim database_table_name As Variant
'You need to set a reference to the below Object Library
'In the Visual Basic Editor do this:
'Tools > References > Microsoft Access Data XX.X Object Library
'The XX.X will be your version of Access......something like this 12.0, 14.0, 16.0 etc....
database_table_name = InputBox("Please Give a Name To The Test You Are Going to Export (No Spaces): ")
With acc
.OpenCurrentDatabase "C:\Users\jt\Desktop\Microsoft_Access\HSS_Test.accdb"
.DoCmd.RunSQL "CREATE TABLE " & database_table_name & " ([Dates] datetime NULL , " & _
"[Demand] DOUBLE , " & _
"[Inventory Position] DOUBLE, " & _
"[On Order] DOUBLE, " & _
"[On Hand] DOUBLE)"
'In the below DoCmd.TransferSpreadsheet statement if your filename is not the file you are working in then
'you will need to update the Filename parameter to your filepath....
'i.e. Filename:= "C:\Users\jt\Desktop\Inventory Policy Analysis.xlsm"
.DoCmd.TransferSpreadsheet _
TransferType:=acImport, _
SpreadSheetType:=acSpreadsheetTypeExcel12Xml, _
TableName:=database_table_name, _
Filename:=Application.ActiveWorkbook.FullName, _
HasFieldNames:=True, _
Range:="Simulation$I1:M100"
.CloseCurrentDatabase
.Quit
End With
Set acc = Nothing
End Sub- Sean SodhaMay 03, 2018Copper Contributor
Thank you so much! I was able to get it to work!!
- Matt MickleMay 03, 2018Bronze Contributor
You're welcome. Glad you were able to get it working! I haven't done Excel to Access coding in a while so I was a bit rusty. It was good to re familiarize myself with the object library!