VB Code Sub GetUserList(FileName As Variant, TableNM As String, PassStr As String, Optional OType As String, Optional RowNum As Long, Optional Password As String) On Error GoTo ErrorHandler ' This sub requires a reference to the Microsoft ActiveX Data Objects 2.x Library Dim Cnct As String, Src As String Dim Connection As ADODB.Connection Dim Recordset As ADODB.Recordset Dim RecI As Integer, RecCnt As Integer ' Open the connection Set Connection = New ADODB.Connection Cnct = "Provider=Microsoft.Jet.OLEDB.4.0; " Cnct = Cnct & "Data Source=" & FileName & ";Jet OLEDB:Database Password=" & PassStr 'Open a database with password Connection.Open ConnectionString:=Cnct Set Recordset = New ADODB.Recordset Select Case OType Case "ReadDB" With Recordset Src = "SELECT * FROM " & TableNM .Open Src, Connection, adOpenStatic, adLockReadOnly, adCmdText ArrUsers = .GetRows RecCnt = .RecordCount - 1 End With For RecI = 0 To RecCnt LogOn.LogUser.AddItem ArrUsers(1, RecI) Next RecI Case "UpdateDB" With Recordset Src = "SELECT * FROM " & TableNM .Open Src, Connection, adOpenDynamic, adLockOptimistic .Move RowNum .Fields(2).Value = Password .Update End With End Select Recordset.Close Connection.Close Set Recordset = Nothing Set Connection = Nothing ErrorHandler: ' clean up If Not Recordset Is Nothing Then If Recordset.State = adStateOpen Then Recordset.Close End If Set Recordset = Nothing
If Not Connection Is Nothing Then If Connection.State = adStateOpen Then Connection.Close End If Set Connection = Nothing
If Err <> 0 Then MsgBox Err.Source & "-->" & Err.Description, , "Error" End If