ADODB read/write access

baitmaster

Well-known Member
Joined
Mar 12, 2009
Messages
2,042
Afternoon all, I'm trying to do something I did a long time ago and can't quite get the code right. Yes it's a botched workaround, but I need to do this approach until further notice...

I'm trying to use a standalone workbook as a database. I have separate workbooks that will control data in and out of that workbook. It's almost working right but I'm having trouble adding records to the recordset...

Connection code
VBA Code:
Public adConn As ADODB.Connection

Sub connectionOpen()

' create ADODB connection object
Set adConn = New ADODB.Connection

' apply settings to connect files
With adConn
    .CursorLocation = adUseServer
    .ConnectionTimeout = 500
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .ConnectionString = "Data Source=" & ThisWorkbook.Path & "\DATABASE.xlsx" & "; Extended Properties=""Excel 12.0; HDR=YES; IMEX=1"";"
    .Open
    .CommandTimeout = 500
End With

End Sub

Recordset code
VBA Code:
Sub submitFormData()

' set database connections
connectionOpen

' declare SQL to get full database contents
Dim strSQL As String: strSQL = "select * from [Data$];"

' create recordset and apply settings
Dim rsDataSet As ADODB.Recordset: Set rsDataSet = New ADODB.Recordset

With rsDataSet
    .CursorLocation = adUseServer
    .Open strSQL, adConn, adOpenStatic, adLockOptimistic, adCmdText
   
    .AddNew

When I try to AddNew I'm getting [Runtime error '2147217911': Cannot update. Database or object is read-only.". I've tried a few different settings in the Connection String and the Recordset settings, how do I open this as read-write?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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