Results 1 to 2 of 2
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    670

    Post Using DLookup In VBA

    I've found multiple examples on search engines on how to use vlookup, but can't find one for how to use it with an int value.

    This is what I have in my VBA and I get an error of
    Code:
    Syntax error in string in query expression 'UserID=70"
    I'm assuming this is because the field I am trying to map to UserID is a Number type.

    This is my full Dlookup statement, what do I need to do to fix this?

    Code:
    If CStr(rst.Fields(i).Value > 5 Then
      a = DLookup("EmpName", "tblEmployeeInfo", "UserID=" & rst.Fields("UserID") & "'")
    End If


  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    ID's are usually numeric. If it is you don't need the single quote. If it is actually text, then you need an extra single quote

    numeric - "UserID=" & rst.Fields("UserID")

    text -
    "UserID='" & rst.Fields("UserID") & "'"

    a shorter way of referring to a field is

    rst!UserID

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

Similar Threads

  1. Shortening if / dlookup >0 / then dlookup
    By Jack Russel in forum Modules
    Replies: 1
    Last Post: 02-19-2016, 03:01 PM
  2. DLookup help
    By mike02 in forum Queries
    Replies: 1
    Last Post: 08-07-2013, 02:29 PM
  3. Dlookup
    By jarvisaurus in forum Queries
    Replies: 4
    Last Post: 01-24-2012, 01:21 PM
  4. dlookup
    By ali zaib in forum Access
    Replies: 3
    Last Post: 01-13-2012, 11:57 AM
  5. Is DLookUp What I should be using?
    By cameronaziz in forum Forms
    Replies: 2
    Last Post: 03-24-2011, 04:29 PM

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