Maybe you are opening the MDB with some multiple use option.
This is what I am using (no LockFile):
VB Code:
Option Explicit 'Reference: M$ ActiveX Data Objects 2.X Library Private Sub Form_Load() Dim strSQL As String Dim rst As ADODB.Recordset Dim cnn As ADODB.Connection On Error GoTo Err_Handler Set rst = New ADODB.Recordset Set cnn = New ADODB.Connection strSQL = "SELECT [LastName] FROM [tblCustomers]" cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Customers.mdb;Persist Security Info=False;" rst.CursorLocation = adUseClient 'Set to enable Cursor movement rst.Open strSQL, cnn, adOpenForwardOnly, adLockOptimistic 'Check RS for data If Not rst.BOF And Not rst.EOF Then rst.MoveFirst 'Load the ListBox with the Last names Do Until rst.EOF List1.AddItem rst.Fields("LastName").Value rst.MoveNext Loop End If rst.Close cnn.Close Set rst = Nothing Set cnn = Nothing Exit Sub Err_Handler: If Not (rst Is Nothing) Then If rst.State = adStateOpen Then rst.Close Set rst = Nothing End If End If If Not (cnn Is Nothing) Then If cnn.State = adStateOpen Then cnn.Close Set cnn = Nothing End If End If MsgBox "Description: " & Err.Description & vbCrLf & _ "Number: " & Err.Number, vbOKOnly + vbInformation, "Error - Called from " & Me.Name & " Sub Form_Load" End Sub




Reply With Quote