VBA Export Data from Excel 2010 to Access 2010 (ADO)

Jonnyb530

New Member
Joined
Jun 10, 2014
Messages
1
Hello. I'm trying to create a macro that exports some user inputs from a spreadsheet in Excel 2010 into a database in Access 2010 (.accdb format). I have done this successfully in the past using a DAO connection and the .mdb format, but now I'm having trouble doing it with an ADO connection.

I have been able to successfully establish a connection to the databse. Here is the top part of my code, which is working properly.

Sub Output()
Dim DBFullName As String
Dim Cnct As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset

' Note Access database resides in same directory as workbook
DBFullName = ThisWorkbook.Path & "\DATABASENAME.accdb"

' Open the connection to the data source.
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct

Set Recordset = New ADODB.Recordset
'**************
Now, I just need to know how to export into the access database. This database has just one table called "input", and I want the macro to create a new record in this table, and populate the fields with the inputs from excel. In the past, I have used code similar to:

'*********
Recordset.Open ("Input")

With Recordset
.AddNew

.Fields("OneField") = Sheets("EXCELSHEETNAME").Range("C3").Value
'Repeat for all fields

End with
'***********
But I keep getting an error message that I cannot perform the recordset.open operation with the ADO connection. Any help is appreciated, thank you!
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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