HI si_the_greek,
I have changed the modCommon.bas as follows:
2 Code:
Option Explicit
Global conData As ADODB.Connection
Global rsData As New ADODB.Recordset
'Public conData As ADODB.Connection
Global SQL As String
Public Sub LoadDatabase()
Set conData = New ADODB.Connection
conData.Provider = "Microsoft.Jet.OLEDB.4.0"
conData.ConnectionString = "Data Source = " & App.Path & "\database.mdb"
conData.Properties("Jet OLEDB:Database Password") = "password"
conData.CursorLocation = adUseClient
conData.Open
End Sub
And have changed the form_load code as below:
2 Code:
Private Sub Form_Load()
SQL = "SELECT * FROM users"
Call LoadDatabase
rsData.Open SQL, conData, adOpenDynamic
DisplayRecord
End Sub
And the code for cmdNext Button remained same:
2 Code:
Private Sub cmdNext_Click()
rsData.MoveNext
If rsData.EOF = True Then
rsData.MoveLast
MsgBox "No More User Exist!", vbInformation, "No User"
Exit Sub
Else
DisplayRecord
End If
End Sub
Using this altered code, I can browse the users table smoothly by next button. But when I Update data by the following:
2 Code:
Private Sub cmdUpdate_Click()
Dim staffName As String
Dim uid As Integer
Dim rsBookmark As Variant
'rsBookmark = rsData.Bookmark
staffName = rsData("uname").Value
uid = rsData("ID").Value
'rsData.Close
If MsgBox("If you click 'Yes', data will be updated." & vbCrLf & "Are you sure to update the data?", vbQuestion + vbYesNo, "Confirm Update") = vbYes Then
SQL = "UPDATE users SET fname='" & txtFname.Text & "',uname='" & txtUser.Text & "',pword='" & txtPassword.Text & "',utype='" & cmboUType.List(cmboUType.ListIndex) & "' WHERE ID=" & uid & ""
Call LoadDatabase
rsData.Open SQL, conData, adOpenDynamic
MsgBox "Record of " & staffName & " has been Updated", vbExclamation, "Record Updated"
'DisplayRecord
'rsData.MoveNext
End If
End Sub
It can update the database correctly. But after that if I press Next Button it shows:

Would you show me the correct code, so that both after form_load and after cmdUpdate_Click I can use cmdNext Button to browse Next Record of user table?