Results 1 to 2 of 2
  1. #1
    funkygoorilla is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    93

    Help with a Dlookup

    Hi, i need some help with a DLookup for a couple columns.


    I have a table names tblUsers with the following fields. User ID, Username, Password. I have a form that I need to code the click event for the OK button to check for a matching username and password. I have the following VBa for the Ok button, but it wont work past the first If condition.
    Code:
    Private Sub btnOk_Click()
    If IsNull(usName) Or IsNull(curPW) Then
    
        MsgBox "You must enter a Username and a Password." _
                & vbCrLf & "Please try again.", vbCritical, _
        "More information required."
        
        Exit Sub
        
        Else
    If IsNull(DLookup("[User ID]", "tblUsers", "[Username]=" & Me.usName & " AND [Password]=" & Me.curPW)) Then
              
              MsgBox "The criteria entered does not match any username and password on file." _
              & vbCrLf & "Check your entries for Username and Password and try again.", vbExclamation, _
              "Need to check criteria."
              
        Exit Sub
              
        
    End If
    
    DoCmd.OpenForm "frmChangePasswordVerify", acViewPreview
    DoCmd.Close acForm, "frmChangePassword"
    
    
        Exit Sub
    End If
    
    End Sub
    Any tips on how to get it to check the values entered into the text boxes on the form called, usName and curPw?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If username and password are string datatypes then you need to enclose the value with single quotes(').
    If IsNull(DLookup("[User ID]", "tblUsers", "[Username]= '" & Me.usName & "' AND [Password]= '" & Me.curPW & "'")) Then

    But often people would use a Dcount and compare the result to 0 to see if a record exists.

    If Dcount(....expression) = 0 Then

    no entry
    else
    other tests
    end if

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

Similar Threads

  1. DLookup example
    By pkstormy in forum Code Repository
    Replies: 1
    Last Post: 07-16-2012, 09:52 AM
  2. Dlookup help
    By justhininabouti in forum Programming
    Replies: 2
    Last Post: 11-26-2011, 10:53 PM
  3. Dlookup help
    By jcaptchaos2 in forum Access
    Replies: 17
    Last Post: 04-21-2011, 01:33 PM
  4. DLookup()
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 09-15-2010, 07:20 AM
  5. Dlookup??
    By Vikki in forum Access
    Replies: 4
    Last Post: 02-16-2010, 07:59 AM

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