Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dlookup Not Working? (a2k (9.0.3821) SR-1 Jet 4.0)

    Dlookup Not Working?
    a2k (9.0.3821) SR-1 Jet 4.0

    I have the following code in a form:

    Dim strZoneCode as String

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dlookup Not Working? (a2k (9.0.3821) SR-1 Jet 4.0)

    Hi John,

    The condition [strZoneCode] = [strZoneCode], like X = X, is always true, so DLookup returns the first value it finds. Try this instead:

    lngZoneID = DLookup("[lngZoneID]", "[tbl_BP_ZoneCode]", "[strZoneCode] = " & Chr(34) & strZoneCode & Chr(34) & ")"

    The above instruction should be on one line. The Chr(34)'s provide double quotes around the string value. Note that there are no square brackets around the second strZoneCode, because that one is a VBA variable, not a field.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dlookup Not Working? (a2k (9.0.3821) SR-1 Jet 4.0)

    Hi Hans

    I finally got the following to work:

    lngZoneID = Nz(DLookup("lngZoneID", "tbl_BP_ZoneCode", "strZoneCode= """ & strZoneCode & """"), "1")

    When I tried:

    lngZoneID = DLookup("[lngZoneID]", "[tbl_BP_ZoneCode]", "[strZoneCode] = " & Chr(34) & strZoneCode & Chr(34) & ")"

    I got Compile error, "Expected list seperator or )"

    Would be interested in your corrected syntex

    Thank, John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dlookup Not Working? (a2k (9.0.3821) SR-1 Jet 4.0)

    John,

    Sorry about that, I went overboard with the quotes. It should have been <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>

    lngZoneID = DLookup("[lngZoneID]", "[tbl_BP_ZoneCode]", "[strZoneCode] = " & Chr(34) & strZoneCode & Chr(34))

Posting Permissions

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