If Then Else Multiple Criteria

oOGrayWolfOo

Registered User.
Local time
Today, 15:31
Joined
Mar 20, 2012
Messages
11
Hello,

I have a custom login page that works

Code:
On Error GoTo ErrorHandler:


    If IsNull([txtLogin]) = True Then 'Check if UserName is blank
        MsgBox "Please type in your ACF2 or login ID."
        
    Else
    
        'Compare value of txtLogin with the saved Logins in Users table and whether Active is "Yes".
        If Me.txtLogin.Value = DLookup("Login", "Users", "[Login]='" & Me.txtLogin.Value & "'") Then
            DoCmd.RunMacro "cmdOK"
            DoCmd.Close acForm, "Login", acSaveNo
            MsgBox "Welcome Back, " & strName, vbOKOnly, "Welcome"
            DoCmd.OpenForm "Main", acNormal, "", "", , acNormal
            
        Else
            MsgBox "Invalid Login or your Access has been Deactivated. Please try again.", vbOKOnly, "Invalid Password"
            intLoginAttempt = intLoginAttempt + 1
            txtLogin.SetFocus
                
        End If
    
    End If

This takes the value entered into the txtLogin control on the Login form and does a little dlookup into the Users Table to find if this txtLogin finds a match in the Login column on the Users table.

What I am having difficulty with is trying to add a second criteria to the "If" statement. Not only do I need to match the Login ID, but i have an Active column which has Yes or No beside each user to identify if they are active or not.

I need the "If" statement to look for a matching Login as I have above, plus look to see if that Login has 'Yes" in the Active column as well.

I tried this and It is not working, no debug error, just lets me log in if I have Yes or No.

Code:
 If Me.txtLogin.Value = DLookup("Login", "Users", "[Login]='" & Me.txtLogin.Value & "'") And Me.txtLogin.Value = DLookup("Login", "Users", "[Active]= Yes") Then

Suggestions?
 
Does this work?

If Me.txtLogin.Value = DLookup("Login", "Users", "[Login]='" & Me.txtLogin.Value & "' And [Active]= Yes") Then
 
Thank you for your response. There was no difference. whether YES or NO I still logged right in.
 
Active is a Yes/No field in that table?
 
Active is not a Yes No Field it is a text field with either Yes or No in it
 
Then try

If Me.txtLogin.Value = DLookup("Login", "Users", "[Login]='" & Me.txtLogin.Value & "' And [Active]= 'Yes'") Then
 
Perfect :) .. worked like a charm. Thank you very much. can I change this post to "solved"?
 
Happy to help. This site doesn't use that feature as far as I know.
 

Users who are viewing this thread

Back
Top Bottom