DB Open Error

  • Thread starter Eddie's Bakery and Cafe'
  • Start date
E

Eddie's Bakery and Cafe'

Hi, when I switch between “Design View†and “Form Viewâ€, I get the following
error.

Run-Time Error …. “The database has been placed in a state by user ‘Admin’
on machine … that prevents if from being opened or locked.â€

I am opening a table and putting its data into collection objects that are
passed back to the caller. The Bug has been giving me troubles for some time.

The error is occurring at line number 26 (conn.Open strConn). If you have
any suggestions they would be greatly appreciated.

1) Public Sub Read_DBTable (ByVal tblName as String, _
2) ByVal dbName as String, _
3) ByRef myCollection as Collection)
4)
5) Dim conn As ADODB.Connection
6) Dim rs As ADODB.recordSet
7) Dim tmpSQLstr As String
8) Dim strConn As String
9) Dim NumOfRows as Integer
10)
11) tmpSQLstr = "SELECT "
12) tmpSQLstr = tmpSQLstr + tblName & ".* "
13) tmpSQLstr = tmpSQLstr + " FROM "
14) tmpSQLstr = tmpSQLstr + tblName
15) tmpSQLstr = tmpSQLstr + " WHERE "
16) tmpSQLstr = tmpSQLstr + tblName
17) tmpSQLstr = tmpSQLstr + ".ForeignKey = 2 "
18) tmpSQLstr = tmpSQLstr + "ORDER BY "
19) tmpSQLstr = tmpSQLstr + tblName
20) tmpSQLstr = tmpSQLstr + ".Name;"
21)
22) strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
23) "Data Source=" & CurrentProject.Path & "\" & dbName & ";"
24)
25) Set conn = New ADODB.Connection
26) conn.Open strConn
27)
28) Set rs = New ADODB.recordSet
29) rs.Open tmpSQLstr, conn, adOpenKeyset, adLockOptimistic
30)
31) If rs.BOF And rs.EOF Then
32) Exit Sub ‘ No Records were found
33) End If
34)
35) NumOfRows = 1
36)
37) Do Until rs.EOF
38) myCollection.Add (rs.Fields.Item(0).value), CStr(numOfRows)
39) NumOfRows = numOfRows + 1
40) rs.MoveNext
41) Loop
42)
43) rs.Close
44) conn.Close
45)
46) Set rs = Nothing
47) Set conn = Nothing
48) End Sub

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top