Results 1 to 4 of 4
  1. #1
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77

    Red face dlookup syntax or am I missing something?

    I've read quite a lot of dlookup examples trying to get the correct syntax, and I keep getting errors. This is what I'm doing...

    On a form, user chooses their name from a combobox cboUserName.
    Combobox is populated with chrUserName from tblUsers.

    I make a public variable strUserName equal that because I'm going to use it for lots of things.
    strUserName = Me.cboUserName

    I know that's working because I then...
    MsgBox strUserName

    and it always returns the correct name.

    So I also want to find that strUserName in the field chrUserName on tblUsers to find the corresponding chrAccessLevel in that record.
    I want it stored in public variable strAccessLevel for use throughout the database.

    I feel this should work:

    strAccessLevel = DLookup("chrAccessLevel", "tblUsers", "chrUserName=strUserName")

    Run-time error '2471':


    The expression you entered as a query parameter produced this error: 'strUserName'

    What am I missing?

  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,652
    See if this helps. Use the form example but with your variable. The key is concatenating the variable into the string, and using text delimiters.

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    pbaldy - You are a star! Great reference. Fixed my issue. Nice and clear. Saved for future ref.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    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. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  2. Syntax error (missing operator)
    By BSJoJaMAx4 in forum Access
    Replies: 5
    Last Post: 08-29-2015, 10:31 PM
  3. Syntax error (missing operator)
    By aamer in forum Access
    Replies: 5
    Last Post: 09-25-2014, 07:36 PM
  4. Syntax error missing operator(3075)
    By parisienne in forum Programming
    Replies: 1
    Last Post: 04-07-2011, 02:29 PM
  5. Syntax Error...missing operator
    By jgelpi16 in forum Programming
    Replies: 14
    Last Post: 09-09-2010, 11:35 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