Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    115

    Unanswered: Multi condition for DLookup

    Multi condition for DLookup
    I have these 2 conditions, but need help to combine them into one.
    Basically only if its the this number exist for this type, then xyz

    If Not IsNull(DLookup("[TypeId]", "tblOrder", "[TypeId] = " & Me.TypeID)) Then xyz
    If Not IsNull(DLookup("OrderNo", "tblOrder", " OrderNo = '" & Me. OrderNo & "'")) Then xyz

    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    dlookup returns the value (if found, if not returns NULL) for a specified column
    so although you can combine multiple conditions as your post title requests, you cannot return multiple columns.

    what you could do however is use a query to return both columns and take appropriate action based on the rows returned.

    I suppose you could use
    Code:
    If (Not IsNull(DLookup("[TypeId]", "tblOrder", "[TypeId] = " & Me.TypeID)) OR
    (DLookup("OrderNo", "tblOrder", " OrderNo = '" & Me. OrderNo & "'"))) Then xyz
    whether you use AND or OR to link the two values is down to what yoru requirements are
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Dec 2013
    Posts
    43
    Provided Answers: 1
    Tom,

    Try:

    Code:
    If (Not IsNull(DLookup("[TypeId]", "tblOrder", "[TypeId] = " & Me.TypeID & " And [OrderNo] = '" & Me.OrderNo & "'"))) Then xyz
    
    But, since you only want to check for the presence of the data, use DCount instead:
    
    If Dcount("[TypeId]", "tblOrder", "[TypeId] = " & Me.TypeID & " AND [OrderNo] = '" & Me.OrderNo & "'") > 0 Then xyz
    hth,
    Wayne

Posting Permissions

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