Help with MsgBox for login VBA

A1CLowe

Registered User.
Local time
Today, 04:13
Joined
Jan 2, 2013
Messages
24
I have a form that requires a username and password to advance further (I know this isn't the most recommended practice, but the people I work with wouldn't know how to get around if they tried.) Now the issue I am having is with adding a MsgBox that pops up when the password doesn't match rather than just do nothing at all if they don't. I am not sure where or how I need to go about adding this since I'm not very VBA savy. What happens when I do put in a msgbox is it just closes the form if it's wrong after you hit ok. If the password is right, it just sits there and doesn't do anything. Hopefully someone can point me in the right direction. All I want to do is set up an error box for when the password is incorrect similar to MsgBox "Password incorrect!", vbRetryCancel, "Password".

Here is my code:

Code:
Private Sub cmdLogin_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer

strUser = Me.txtUser
If DCount("[TechPWD]", "Technicians Extended", "[Technician Name]='" & Me.txtUser & "'") > 0 Then
    strPWD = DLookup("[TechPWD]", "Technicians Extended", "[Technician Name]='" & Me.txtUser & "'")
    If strPWD = Me.txtPWD Then
        intUSL = DLookup("[SecurityGroup]", "Technicians Extended", "[Technician Name]='" & Me.txtUser & "'")
        Forms!frmUSL.txtUN = strUser
        Forms!frmUSL.txtUSL = intUSL
        Select Case intUSL
            Case 1
                DoCmd.OpenForm "Home", acNormal
            Case 2
                DoCmd.OpenForm "Home", acNormal, , , acFormReadOnly
            Case 3
                MsgBox "Not configured yet", vbExclamation, "Not configured"
            Case 4
                MsgBox "Not configured yet", vbExclamation, "Not configured"
        End Select
        DoCmd.Close acForm, "Login Dialog", acSaveNo
    End If
End If
        


End Sub
 
You'd add an Else clause to this If/Then block:

If strPWD = Me.txtPWD Then

and add your message box there.
 
Is this what you meant?

Because this just closes my form after I hit retry and proceeds as if I put in the right password.

Code:
Private Sub cmdLogin_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer

strUser = Me.txtUser
If DCount("[TechPWD]", "Technicians Extended", "[Technician Name]='" & Me.txtUser & "'") > 0 Then
    strPWD = DLookup("[TechPWD]", "Technicians Extended", "[Technician Name]='" & Me.txtUser & "'")
    If strPWD = Me.txtPWD Then
          Else
             MsgBox "Password incorrect", vbRetryCancel, "Password"
        intUSL = DLookup("[SecurityGroup]", "Technicians Extended", "[Technician Name]='" & Me.txtUser & "'")
        Forms!frmUSL.txtUN = strUser
        Forms!frmUSL.txtUSL = intUSL
        Select Case intUSL
            Case 1
                DoCmd.OpenForm "Home", acNormal
            Case 2
                DoCmd.OpenForm "Home", acNormal, , , acFormReadOnly
            Case 3
                MsgBox "Not configured yet", vbExclamation, "Not configured"
            Case 4
                MsgBox "Not configured yet", vbExclamation, "Not configured"
        End Select
        DoCmd.Close acForm, "Login Dialog", acSaveNo
    End If
End If
        


End Sub
 
No.

If ...
What to do if true
Else
What to do if not
End If
 
Wow.. I don't know what I was thinking.... It's been a very, very long day. Thank's a million!!
 

Users who are viewing this thread

Back
Top Bottom