Hi,
I have a run time error 2447: Invalid use of .(dot)or ! operator or invalid parenthese.
I have a yellow hightligth on the section of "While UserName <> ""
This is my code:
Private Sub cmdAdd_Click()
Dim strSysAdminFlag
If IsNull(Me.txtUserName) Then
MsgBox "Please enter a username", vbOKOnly, "Entry Error!"
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please enter a password", vbOKOnly, "Entry Error!"
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please confirm the entered password", vbOKOnly, "Entry Error!"
Exit Sub
End If
If txtPassword = txtPasswordConf Then
DoCmd.GoToRecord , , acFirst
While UserName <> ""
If txtUserName = UserName Then
MsgBox "User already exists. System cannot add user.", vbOKOnly, "Entry Error!"
UserName = ""
UserName.SetFocus
Exit Sub
End If
DoCmd.GoToRecord , , acNext
Wend
Dim Msg, Style, Title, Response
Msg = "This will add user " & txtUserName & " to the system. Are you sure you want to add this user?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Add User" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Else: Exit Sub
End If
Else
MsgBox "Passwords do not match", vbOKOnly, "Entry Error!"
txtPassword = ""
txtPasswordConf = ""
txtPassword.SetFocus
Exit Sub
End If
DoCmd.GoToRecord , , acNewRec
UserName = txtUserName
Password = txtPassword
MsgBox "User " & txtUserName & " has been added.", vbOKOnly, "Update success"
txtUserName = ""
txtPassword = ""
txtPasswordConf = ""
UserName.Visible = False
Password.Visible = False
DoCmd.GoToRecord , , acNewRec
txtPasswordConf.Enabled = False
txtUserName.SetFocus
cmdAdd.Enabled = False
cmdDisregard.Enabled = False
txtUserName.SetFocus
End Sub
I have a run time error 2447: Invalid use of .(dot)or ! operator or invalid parenthese.
I have a yellow hightligth on the section of "While UserName <> ""
This is my code:
Private Sub cmdAdd_Click()
Dim strSysAdminFlag
If IsNull(Me.txtUserName) Then
MsgBox "Please enter a username", vbOKOnly, "Entry Error!"
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please enter a password", vbOKOnly, "Entry Error!"
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please confirm the entered password", vbOKOnly, "Entry Error!"
Exit Sub
End If
If txtPassword = txtPasswordConf Then
DoCmd.GoToRecord , , acFirst
While UserName <> ""
If txtUserName = UserName Then
MsgBox "User already exists. System cannot add user.", vbOKOnly, "Entry Error!"
UserName = ""
UserName.SetFocus
Exit Sub
End If
DoCmd.GoToRecord , , acNext
Wend
Dim Msg, Style, Title, Response
Msg = "This will add user " & txtUserName & " to the system. Are you sure you want to add this user?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Add User" ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Else: Exit Sub
End If
Else
MsgBox "Passwords do not match", vbOKOnly, "Entry Error!"
txtPassword = ""
txtPasswordConf = ""
txtPassword.SetFocus
Exit Sub
End If
DoCmd.GoToRecord , , acNewRec
UserName = txtUserName
Password = txtPassword
MsgBox "User " & txtUserName & " has been added.", vbOKOnly, "Update success"
txtUserName = ""
txtPassword = ""
txtPasswordConf = ""
UserName.Visible = False
Password.Visible = False
DoCmd.GoToRecord , , acNewRec
txtPasswordConf.Enabled = False
txtUserName.SetFocus
cmdAdd.Enabled = False
cmdDisregard.Enabled = False
txtUserName.SetFocus
End Sub