Database locked - why?

Lol Owen

Registered User.
Local time
Today, 00:54
Joined
Mar 15, 2004
Messages
86
Hi all, trying to create a recordset through ADO in Access. Got my code behind a button on a form (just at experimental stage). I have replicated the code from that I used in a VB form on a different project but when I try to9 execute the code I just keep getting an eror message with " the database has been set in a state that prevents it being opened or locked". I've got no tables or other forms opened so what's the deal? My code is as below:

Private Sub Command0_Click()
Dim cnABOF As ADODB.Connection
Dim rsUser As ADODB.Recordset
Dim strConnection As String
Set cnABOF = New ADODB.Connection
Set rsUser = New ADODB.Recordset
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "C:\Documents and Settings\Lol\Desktop\Project 26th March\Database\French.mdb;" ' text for connectionSet rsUser = New ADODB.Recordset
cnABOF.Open strConnection

With rsUser
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "tblUser", cnABOF, , , adCmdTable

.MoveFirst

End With

End Sub

Hope someone can shed some light, thanks, Lol :D
 
The way I read it, you are possible both instances;)

If you're working on the same database as your tables are in, substitute all the connection stuff with

Set cnABOF = currentproject.connection ' connection to current db

which will also work on linked tables.
 
Thanks Roy, will give it try! I've read so many books of late it's all starting to blur a bit ;) Sometimes I forget the straightforwarsd stuff!

Cheers, Lol :D
 

Users who are viewing this thread

Back
Top Bottom