Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    26

    Unanswered: DLookup with Variable

    I am trying to use DLookup with the criteria being equal to a variable. Goes as follows.
    Dim class1 as String, DestState as String
    DestState = "NY"
    class1 = DLookup("[StCode]", "tblEagleCodes", "[State] = " & DestState)

    but I keep getting this error.
    The expression you entered as a query parameter produced this error: 'The object doesn't contain the Automation object 'NY.''

    I know what you are going to say, its not in the table, but I assure you the value is listed in my table, tblEagleCodes.

    Any thoughts on what is wrong, maybe syntax I'm overlooking?

    Thanks.
    Life's a bowl of punch, go ahead and spike it.

  2. #2
    Join Date
    Sep 2002
    Location
    Finland
    Posts
    34

    Re: DLookup with Variable

    Use ' around NY

    DestState = "'NY'"
    Or
    class1 = DLookup("[StCode]", "tblEagleCodes", "[State] = '" & DestState & "'")

  3. #3
    Join Date
    Jul 2003
    Posts
    26
    Worked like a charm, thank you very much.
    Life's a bowl of punch, go ahead and spike it.

Posting Permissions

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