Code:
Private Sub Command7_Click()
Dim strOldPassword As String
Dim strSQL As String
Dim intUserID As Integer
Dim vMsg, vStat
txtUser = Environ("Username")
'If IsNull(Me.txtUser) Or Me.txtUser = "" Then
' MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
' Me.txtUser.SetFocus
' Exit Sub
'End If
vMsg = ""
vStat = "Error"
Select Case True
Case IsNull(txtPassword)
vMsg = "You must enter a Password."
txtPassword.SetFocus
Case txtPassword = ""
vMsg = "You must enter a Password."
txtPassword.SetFocus
Case IsNull(txtPassword2)
vMsg = "You must enter a Password."
txtPassword2.SetFocus
Case txtPassword2 = ""
vMsg = "You must enter a NEW Password."
txtPassword2.SetFocus
Case IsNull(txtConfirmPW)
vMsg = "You must enter a Confirmation New Password."
txtPassword2.SetFocus
Case txtConfirmPW = ""
vMsg = "You must enter a Confirmation New Password."
txtConfirmPW.SetFocus
Case txtConfirmPW <> txtConfirm2
vMsg = "New password and Confirmation Password do not match."
txtConfirmPW.SetFocus
End Select
If vMsg = "" Then
strOldPassword = DLookup("[Password]", "tblUsers", "[UserID]=" & intUserID)
If txtPassword <> strOldPassword Then
vMsg = "The Old Password does not match"
Else
strSQL = "UPDATE tblUsers SET Password=" & "" & Me.txtPassword2 & "'WHERE UserID=" & Me.txtUserID
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
vMsg = "Password has been changed"
vStat = "Success"
End If
MsgBox vMsg, vbCritical, vStat
End Sub