Results 1 to 11 of 11
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Another Dlookup ?

    I have:


    DLCH1: DLookUp("[parent_equipment_item_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'")

    This works as the ID's are numbers

    and want to add:
    [Equip Lin]="XXB840"

    it is a string

    DLCH1: DLookUp("[parent_equipment_item_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "' AND [Equip Lin]=XXB840") = #Error

    I know it has to do with the " and '

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try:
    Code:
    DLCH1: DLookUp("[parent_equipment_item_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "' AND [Equip Lin]='XXB840'")

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I think I am having an absolute brain cramp.

    I am wanting to look up the parent_unique_item_id with [Equip LIN] = XXB840 that is equal to unique_id with [Equip Lin] = Z05072


    I have tried several iterations without success. I get an null out, but no errors. I did try your example and get a null out. Wich is correct as I don't get an error.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you say

    This works as the ID's are numbers
    but this

    "[unique_id] ='" & [parent_equipment_item_id] & "'"

    is treating them as strings

    to treat as numbers you would have

    "[unique_id] =" & [parent_equipment_item_id]

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I guess they are considered as a string then. I see numbers, but didn't check the cell type.

    DLCH1: DLookUp("[parent_equipment_item_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'")

    This does provide numbers, but it shows uyp under XXB480 and XXB481 LINS, so it is technichally wrong.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    go with JoeM's solution then

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I am wanting to look up the parent_unique_item_id with [Equip LIN] = XXB840 that is equal to unique_id with [Equip Lin] = Z05072
    In that description, you said that the value you want must be "equal to unique_id with [Equip Lin] = Z05072"

    So all you need is this:

    UniqueID_1 = DLookUp("[unique_id]","[Data]"," [Equip Lin] = 'Z05072')


    I'm not sure that is what you really want - but that's what your description says.

  8. #8
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I used this to get around it:

    DLCH1: IIf([Equip LIN]="XXB840",DLookUp("[unique_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'"),"")

    DLCH2: IIf([Equip LIN]="XXB841",DLookUp("[unique_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'"),"")

    I'd prefer not to use the IIF statement and I know there's a more eloquent way of doing it with just the DLookup. Maybe the code explains it better than I can.

    If query is on a row where the [Equip Lin] = XXB840, then find the Unique ID elsewhere in the query where it equals the parent_equipment_item_id and [Equip Lin] = Z05072.

    Example:

    [Equip Lin] Unige_ID Parent_..._id
    XXB840 123456 123454
    XXB841 123457 123454
    Z05072 123454 120019

    Z05072 = Radio
    XXB840 = Channel 1
    XXB841 = Channel 2

  9. #9
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If query is on a row where the [Equip Lin] = XXB840, then find the Unique ID elsewhere in the query where it equals the parent_equipment_item_id and [Equip Lin] = Z05072.
    That doesn't make sense. You are trying to find a [Unique ID] value when you already know the value you want - it is in [parent_equipment_item_id] of the current query row.

    Your dlookup : DLookUp("[unique_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'")

    Is doing just that. However, you are using it in an Iif which returns an empty string if the DLookup does not find a match - is that the object of the exercise?

  10. #10
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    "However, you are using it in an Iif which returns an empty string if the DLookup does not find a match - is that the object of the exercise?"

    yes, that was my intentions.

    That radio is not the only radio in the db, and in this instance the radio count exceeds 150. There are many more and they all use the XXB840/1 [Equip LIN].

    So if the Equip Lin = that radio, then I need to know the unique_ID so that I can search the parent.._ID that matches the radios unique_ID and then have separation between channel 1 and channel 2. They are assigned different nets.

  11. #11
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    I figured it out finally. This is/was my intent:
    DLCH1: IIf([Equip LIN]="XXB840",DLookUp("[unique_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'" & " And [Equip Lin]='Z05072'"),"")
    DLCH2: IIf([Equip LIN]="XXB841",DLookUp("[unique_id]","[Data]","[unique_id] ='" & [parent_equipment_item_id] & "'" & " And [Equip Lin]='Z05072'"),"")

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
    By Alex Motilal in forum Programming
    Replies: 2
    Last Post: 04-20-2015, 11:05 PM
  3. Like in Dlookup
    By msp4422 in forum Programming
    Replies: 3
    Last Post: 02-19-2013, 04:02 PM
  4. DLookup
    By smidgey in forum Forms
    Replies: 13
    Last Post: 01-19-2011, 09:27 AM
  5. DLookup Help
    By Alex Motilal in forum Queries
    Replies: 3
    Last Post: 01-17-2011, 02:01 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