I am trying to use excel as a front end to update an access database with user inputs. However, I can not get this query to function properly. Currently, I have gotten the error message;
Run-time error '-2147467259 (80004005)': Cannot Update. Database or object is read-only.
I know the file is not stored in a location that is write protected and the file itself is not either. Opening the file itself on any users computer will allow them to write to it, but the code is blocking itself somehow. This is Excel and Access 2007. Code below;
Sub PopulateOneField()
Const TARGET_DB = "P:\Master\Part Number List.accdb"
Dim cnn As ADODB.Connection
Dim MyConn
Dim rst As ADODB.Recordset
Dim i As Long, j As Long
Dim Rw As Long
Dim sSQL As String
Sheets("Sheet2").Activate
Rw = Range("A65536").End(xlUp).Row
Set cnn = New ADODB.Connection
MyConn = TARGET_DB
MyConn = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" & MyConn
With cnn
.Open MyConn
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
For i = 3 To Rw
sSQL = "SELECT * FROM sheet2"
rst.Open Source:=sSQL, _
ActiveConnection:=cnn, _
CursorType:=adOpenKeyset, _
LockType:=adLockOptimistic
rst(Cells(1, 3).Value) = Cells(i, 3).Value
rst.Update
rst.Close
Next i
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
Thanks in advance.
Sheet2? I use:cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source='P:\Master\Part Number List.accdb'". Missingrst.EditMode. Should probably open recordset outside the loop.