Results 1 to 4 of 4
  1. #1
    CDRCHOP is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    2

    Query with DLookUp and "Or" stements in the return

    I am having trouble with a simple query using the DLookUp function. I am using the DLookUp function to look up values in a field in a "temp" table (holds a single record of data that changes). The DLookUp function works fine when the "temp" table field I am performing the lookup has a single name. I also have instances when the field will be populated with multiple names with an "Or" between the names. For example, the query works fine when there is just one name..."Name1"...but if I have the field in the "temp" table showing text of ("Name1" Or "Name2") then the result doesn't work. I think the DLookUp result is only seeing this entire string as pure text and not separating the text as "Or" statements. Is there a way to force the query to see this as "Or" statements vice pure text?



    I am trying to get away from using more complicated logic of separating the string into smaller pieces and using the "Or" statement in between multiple names.

    Thank you!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    Do NOT use Dlookup in a query. The QUERY is the Dlookup.
    you do this by joining your data table to the lookup table.
    the criteria is either in a form or the query.

  3. #3
    CDRCHOP is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2017
    Posts
    2
    Not sure what you mean. I have been using Access since the mid 90's and I routinely use DLookUp in queries. I have a unique instance where I have a single field that holds a name but in 2 instances the field holds multiple names separated by "Or" and I am trying to figure out a way for the DLookUp function to recognize this as an Or statement. Example...."Name1" Or "Name2" vice "Name1 or Name2." I can manually copy and paste the field contents into the query and it works fine but when using the DLookUp function it sees the entire string as text and of course doesn't work as intended.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,894
    Maybe:

    DLookup("somefield", "sometable", "fieldname LIKE '*" & [fieldname] & "*'")

    or

    DLookup("somefield", "sometable", "InStr(fieldname, '" & [fieldname] & "')>0")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Return All Query Names Where Text Like ""
    By jo15765 in forum Macros
    Replies: 2
    Last Post: 01-26-2017, 02:34 PM
  2. Replies: 5
    Last Post: 03-22-2013, 01:11 PM
  3. Replies: 2
    Last Post: 11-14-2012, 04:47 PM
  4. Replies: 3
    Last Post: 06-29-2012, 08:54 AM
  5. Replies: 4
    Last Post: 03-23-2012, 01:18 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