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
Recordset code
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?
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?