Results 1 to 11 of 11
  1. #1
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97

    Help with DLookUp

    I have 2 forms ("X" and "Y") linked by field ID.
    I have a query called "Z" counting records in "Y" that have a common ID.


    I would like to add a text field on form "X" showing the result in the field "W" of the query "Z" for the current ID.
    I have put in control source of such text field the following :

    =DLookUp([CountOfW], [Z], "ID=" & Me.ID)

    I receive the error #Name? in the text field in form view.
    What's wrong in my syntax ?

  2. #2
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    Change [Z] to "Z"

    =DLookUp([CountOfW], "Z", "ID=" & Me.ID)

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    =DLookUp("[CountOfW]", "Z", "ID=" & Me.ID)

    might have to play with the " marks around the criteria section of the dlookup, I didn't test.

  4. #4
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Actually I just discovered that in most non-US laptops the commas should be replaced by semicolons (sort of system settings) in order for the syntax to be accepted ! So the right one for me is :

    =DLookUp("[CountOfW]";"Z";"[ID] = ...")

    It works when I put a number in place of ..., but not when I place a call to current ID on form X. I have tried

    =DLookUp("[CountOfW]";"Z";"[ID] = Forms!X![ID]")
    and
    =DLookUp("[CountOfW]";"Z";"[ID] = Me.[ID]")

    but none of them works. Any suggestion ?

    P.S. : ID is an autonumber field, so no single quotes should be needed in my opinion...

  5. #5
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    focosi -

    You could try...

    =DLookUp("[CountOfW]";"Z";"[ID]=" & Forms!X![ID])

    instead of

    =DLookUp("[CountOfW]";"Z";"[ID] = Forms!X![ID]")

    Just a thought.

    Jim

  6. #6
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Quote Originally Posted by ketbdnetbp View Post
    You could try...

    =DLookUp("[CountOfW]";"Z";"[ID]=" & Forms!X![ID])

    instead of

    =DLookUp("[CountOfW]";"Z";"[ID] = Forms!X![ID]")

    Just a thought.

    Jim
    still not working ... blank values... very frustrating....

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Make sure that there are no controls on this form which have the same name as any of the fields being used here. If there are, rename the controls. When using formulas none of the controls being referred to can have the same name as the fields they are bound to or it gives an error.

  8. #8
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2003
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    focosi -

    Just as a test, try running this code somewhere on Form "X" and see what happens...

    dim lngID as Long
    dim lngID1 as Long
    lngID = Me.[ID]
    lngID1 = [Forms]![X]![ID]
    MsgBox "First Value: " & lngID
    MsgBox "Second Value: " & lngID1

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    =DLookUp("[CountOfW]", "Z", "ID=" & Me.ID & ")

    Forgot the closing & " mark

  10. #10
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    thanks for help I actually discovered that it was a matter of using ; instead of , on non-US PC.
    Further, blank values were due to the fact that my query didn't include [ID] field from form "X". Now everything works. Thanks for help!

  11. #11
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by rpeare View Post
    =DLookUp("[CountOfW]", "Z", "ID=" & Me.ID & ")

    Forgot the closing & " mark
    Actually rpeare, there should NOT be a closing " at the end. If ID is not text then it would be:

    =DLookUp("[CountOfW]", "Z", "ID=" & Me.ID)

    or if needing the semi-colons as stated:

    =DLookUp("[CountOfW]"; "Z"; "ID=" & Me.ID)

    The extra quote at the end should generate an error.

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

Similar Threads

  1. DLookup example
    By pkstormy in forum Code Repository
    Replies: 1
    Last Post: 07-16-2012, 09:52 AM
  2. DLookUp Help
    By ThaGreenMoose in forum Forms
    Replies: 10
    Last Post: 06-15-2011, 12:08 PM
  3. DLookup help
    By denners05 in forum Access
    Replies: 1
    Last Post: 06-11-2011, 12:55 PM
  4. Need help with dlookup.
    By Keith in forum Database Design
    Replies: 8
    Last Post: 05-24-2010, 06:28 PM
  5. Dlookup
    By janjan_376 in forum Access
    Replies: 20
    Last Post: 07-07-2009, 07:40 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