Results 1 to 6 of 6
  1. #1
    GrayWolf is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    12

    If Then Else Multiple Criteria

    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?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    As answered elsewhere, does this work?

    If Me.txtLogin.Value = DLookup("Login", "Users", "[Login]='" & Me.txtLogin.Value & "' And [Active]= Yes") Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GrayWolf is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    12
    Thank you for your response. There was no difference. whether YES or NO I still logged right in.

  4. #4
    GrayWolf is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    12
    This Worked like a charm. Thank you
    Code:
    If Me.txtLogin.Value = DLookup("Login", "Users", "[Login]='" & Me.txtLogin.Value & "' And [Active]= 'Yes'") Then

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem. As discovered elsewhere, the field is Text rather than Yes/No, so the single quotes were required around the value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Monest, what is the purpose of all your posts? Are you preparing to spam? If you actually disagree, what with?

    Edit: I found the user was spamming so deleted all posts.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple criteria in a SQL query
    By Huddle in forum Queries
    Replies: 2
    Last Post: 02-29-2012, 03:32 PM
  2. Multiple criteria query
    By jwb257 in forum Queries
    Replies: 6
    Last Post: 10-21-2011, 02:29 PM
  3. Iif statement with multiple criteria
    By coach32 in forum Queries
    Replies: 1
    Last Post: 09-07-2011, 01:28 AM
  4. list box with multiple criteria
    By white_flag in forum Access
    Replies: 6
    Last Post: 07-25-2011, 11:25 AM
  5. Replies: 1
    Last Post: 07-13-2011, 11:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums