I have this code below. Everything works except for this line: If Not IsNull(Answer) And Me.txtUsername = Dirty Then
I really just need to add the dirty command to this line of code but don't know how in VBA can someone help with this? Sometimes I need to change the password of a user and this code searches to make sure that the username is not used more than once and since I am saving the record by editing the password, it finds that the username is already in use so I have to change the user name slightly different just to save the new password then change the username back to what it was then save again. Thanks for the help.
Private Sub cmdSaveRecord_Click()
Dim Answer As Variant
Answer = DLookup("Username", "tblUser", "Username = '" & Me.Username & "'")
If Not Me.Dirty Then
MsgBox "No Changes Were Made.", vbInformation, "Notification"
DoCmd.GoToControl "[txtEmpName]"
Exit Sub
End If
If Not IsNull(Answer) And Me.txtUsername = Dirty Then
MsgBox "Username Already In Use." & vbCrLf & vbCrLf & "Please Enter A Different Username." _ , vbInformation, "Requirements"
Me.txtUsername.SetFocus
DoCmd.CancelEvent
Exit Sub
End If
If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToRecord , , acPrevious
DoCmd.GoToRecord , , acNext
DoCmd.GoToControl "[txtEmpName]"
End If
End Sub