Results 1 to 4 of 4

Thread: Dlookup Syntax

  1. #1
    Join Date
    Nov 2005
    Posts
    79

    Unanswered: Dlookup Syntax

    I have been struggling with this for hours. I am unsure if I am taking the right approach or should do this another way. Any help would be greatly appreciated. This is for a user login form. I am making attempts to check and see if the password is valid against the username and if it is, then wanting to check to see if the [Password] is equal to the default word Password (assigned upon intially creating the record). Any help would be greatly appreciated. This is what I have been working and re-working. Thanks in advance.

    Code:
    If Me.txtPassword.Value = DLookup("[Password]", "tblUserLogin", "[Username] = ' & Me.cboUsername.Value and [Password]='Password' & "'"") Then

  2. #2
    Join Date
    Sep 2013
    Posts
    1
    Try this
    Code:
    DLookup("[Password]", "tblUserLogin", "[Username] = '" & Me.cboUsername.Value & "'and [Password]='Password' & "'"")

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    writing your code as you have makes it harder to debug
    assigning the more complex bits to a variable makes debugging easier
    Code:
    dim strWhereClause as string
    strWhereClause = "[Username] = ' & Me.cboUsername.Value & "' and [Password]= '" & Password & "'"
    If Me.txtPassword.Value = DLookup("[Password]", "tblUserLogin", strWhereClause) Then
    if you don't want to set a breakpoint then out put the value of strwherclause to the immediate window or a msg box. that way round you cna see if your code 'looks' right. just because code compiles (ie runs) in Access doesn't mean its valid SQL
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Nov 2005
    Posts
    79

    Thumbs up Thank You Tdecker & Healdem

    A big shout out to both of you two. I tried both solutions and couldn't get them to work, but I started looked at both codes and noticed similiaries such as the use of " (double quotes before and after the &). I sure hope that I can always remember this. Healdem, I will try and code by breaking down my strings, as it did indeed make it much easier.

    I always want to post the final solution because this site and the help given is always invaluable. This is my final solution.

    Code:
    Dim strWhereClause As String
    strWhereClause = "[Username] ='" & Me.cboUsername.Value & "' And [Password]='Password' "
    If Me.txtPassword.Value = DLookup("[Password]", "tblUserLogin", strWhereClause) Then
    Thank you again for all of your assistance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •