Hi,
Basically I have a problem with registering to my quiz system. I had
borrowed some code from an existing program but I just do not know why
it doesn't work.
If (txtUsername = "" Or txtPassword = "") Or (txtFirstName = "" Or
txtLastName = "") Then
MsgBox "Please complete all the fields", vbCritical = vbOKOnly,
"Incomplete Login Details"
txtFirstName.Se tFocus
Else
Set rs = rs.Open("SELECT * FROM Login"), ......
'add new account to login database
With rs
.AddNew
!UserName = Trim(txtUsernam e)
!Password = Trim(txtPasswor d)
!FirstName = Trim(txtFirstNa me)
!LastName = Trim(txtLastNam e)
On Error GoTo duplicate
.Update
MsgBox "Congratulation s! You can use the system now.",
vbInformation, "Details entered"
duplicate:
'Err 3022 is an error code for duplicate ID
If Err = 3022 Then
MsgBox "Username already in use. Please enter a different
Username.", vbOKOnly, "Duplicate Username"
.CancelUpdate
txtUsername = ""
txtPassword = ""
txtFirstName = ""
txtLastName = ""
txtUsername.Set Focus
Exit Sub
End If
Resume Next
Unload Me
frmLogin.Show
End With
End If
Well it's not that it doesn't work, it bypasses the error message. If
I enter a duplicate username, it gives me a success message rather
than an error. However, it does run the .cancelupdate function. I am
catering for an error in the Err = 3022 if statement, which is an
error code for duplicate entry of a primary key.
Please someone tell me what am I doing wrong here and how to rectify
the problem, I'll be really appreciated.
Basically I have a problem with registering to my quiz system. I had
borrowed some code from an existing program but I just do not know why
it doesn't work.
If (txtUsername = "" Or txtPassword = "") Or (txtFirstName = "" Or
txtLastName = "") Then
MsgBox "Please complete all the fields", vbCritical = vbOKOnly,
"Incomplete Login Details"
txtFirstName.Se tFocus
Else
Set rs = rs.Open("SELECT * FROM Login"), ......
'add new account to login database
With rs
.AddNew
!UserName = Trim(txtUsernam e)
!Password = Trim(txtPasswor d)
!FirstName = Trim(txtFirstNa me)
!LastName = Trim(txtLastNam e)
On Error GoTo duplicate
.Update
MsgBox "Congratulation s! You can use the system now.",
vbInformation, "Details entered"
duplicate:
'Err 3022 is an error code for duplicate ID
If Err = 3022 Then
MsgBox "Username already in use. Please enter a different
Username.", vbOKOnly, "Duplicate Username"
.CancelUpdate
txtUsername = ""
txtPassword = ""
txtFirstName = ""
txtLastName = ""
txtUsername.Set Focus
Exit Sub
End If
Resume Next
Unload Me
frmLogin.Show
End With
End If
Well it's not that it doesn't work, it bypasses the error message. If
I enter a duplicate username, it gives me a success message rather
than an error. However, it does run the .cancelupdate function. I am
catering for an error in the Err = 3022 if statement, which is an
error code for duplicate entry of a primary key.
Please someone tell me what am I doing wrong here and how to rectify
the problem, I'll be really appreciated.
Comment