Results 1 to 5 of 5
  1. #1
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239

    DLookup function - need help

    Hi,

    I have a continous form (named "Search"), for which I have shortcut menu to open another form. Code for that is :

    Code:
    DoCmd.OpenForm "Results", , , "ID_Results=" & Forms![Search]![Search_Subform].Form![ID_Search]
    This code opens form Results and displays records, that are linked by one to many relationship, via ID.



    What I want on this form (Results) is to show record with same ID from "Search" form.

    So basically, I want a Lookup in textboxes, that will show for what record of "Search" form I'm watching Results.

    I tried his :

    Code:
    =DLookUp("Name";"Search";"ID_Search= Search.ID_Search")
    This code doesn't produce any errors, but It shows only first record all the time. I want Lookup to show record I selected in "Search" form. Everything else I tried, produced errors.

    Can somebody tell me what I'm doing wrong ??

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    You aren't doing anything wrong. That's how DLookup works.

    From M$oft:
    If more than one field meets criteria, the DLookup function returns the first occurrence. You should specify criteria that will ensure that the field value returned by the DLookup function is unique.

  3. #3
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    thanks for response Orange.

    My criteria to return should be record that I selected. But I'm not sure how to make field value unique ?

    In my Results table I have ID_Search, this ID links my Search table as I said (one to many relationship). But If I do It like this, I get an error :

    Code:
    =DLookUp("Name";"Search";"Results.ID_Search= Search.ID_Search")
    Same error If I mix them opposite.

  4. #4
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    I figured out, stupid. I didn't know I can use same synthax in DLookup as used when I open form Results. This is solution:

    Code:
    =DLookUp("Name";"Search";"ID_Search=" & Forms![Search]![Search_Subform].Form![ID_Search])
    Problem is that DLookup returns me #Error for fields that are "empty" in Search record. Can I replace this with just an empty string, Nz doesn't work ??

  5. #5
    Lukael is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    239
    I solved that also:

    Code:
    =DLookUp("Name";"Search";"ID_Search=" & Nz(Forms![Search]![Search_Subform].Form![ID_Search];0))
    Now Nz function works !

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

Similar Threads

  1. Dlookup Function
    By balajigade in forum Access
    Replies: 2
    Last Post: 09-10-2015, 01:55 AM
  2. Dlookup function Help
    By bronson_mech in forum Forms
    Replies: 20
    Last Post: 07-07-2013, 05:04 AM
  3. Dlookup Function
    By MarkHenderson in forum Queries
    Replies: 1
    Last Post: 11-19-2012, 03:00 PM
  4. DlookUp Function.
    By cap.zadi in forum Forms
    Replies: 11
    Last Post: 09-22-2011, 12:56 PM
  5. Need Help for Dlookup function
    By wasim_sono in forum Programming
    Replies: 5
    Last Post: 01-04-2006, 08:18 AM

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