openingdatabase using ADO
hi,
when i try to run this code i get an error that says that "the database has been placed in a state by the user that does not allow it to be opened or locked."
what am i doing wrong? its my first time using ADO and i cant get pass this stage.
VB Code:
Private Sub Command116_Click()
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset, rstCln As New ADODB.Recordset
Dim CurDB As Database
Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection
With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source= " & CurDB.Name
.Open
End With
Set rst = New ADODB.Recordset
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic
rst.Open "SELECT * FROM equips WHERE [Village name] = '" & Me![Village name] & "'", CurConn, , , adCmdText
End sub
Re: openingdatabase using ADO
If you are in Access you can use CurrentProject.connection to get the active connection.
The error is because when you double click Access Mdb files it opens in Access as exclusive (for some reason). If you close the mdb and reopen through Access file>Open it should let you run the code and connect. But as I pointed out above there is already an open connection to the current database.