Results 1 to 7 of 7
  1. #1
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26

    Error using textbox value in dlookup criteria

    The problem I'm having is that Access doesn't like me comparing the value of a textbox to the value in one of my tables. I'll list everything because its small and I can explain things easier.

    3 Tables:
    1) "Properties". Headers "ID", "Property". Indexed values of "Mascara", "Foundation", "Nails"
    2) "ICs". Headers "IC", "Property_FK". Indexed values for "IC" of the numbers 1-5 as numbers. 1 and 2 are mascara, 3 and 4 are foundation, 5 is nails. Property_FK is in a relationship with property from "Properties" (combobox dlookup for values). [IC = Item Code]
    3) "pH Test". Headers "Property_FK", "pH". Again property is pulled directly from the properties table. pH column is a yes/no box. values can be whatever, for this test I had mascara and foundation as yes's.


    1 Form:


    1) "Login".
    "cbIC". Combobox that pulls values from "ICs" to list the Item Codes.
    "tbProp". Textbox that pulls Property from "ICs" using the IC as a lookup.
    "tbPH". Textbox that will display an "X" if the box is checked in pH test.

    The combobox and textbox work fine. As I change selections in the combobox the property box updates accordingly. The problem is getting the tbPH box to work.
    Code:
     If(DLookUp("[pH]", "pH Test", "[Property_FK]="& "[tbPH].[Value]","X","")
    is the closest thing that I have gotten to work. The problem is that it is not updating as new ICs are selected, it is just sticking with the initial value and not changing. I've made a test textbox and [tbPH].[Value] works and updates as necessary. The problem is that in the DLookUp function if I drop the quotes around tb.value I get an error. So I'm not entirely sure what syntax I need to get it right or if I need to store my data in a different format to make the comparison work like I want it to.

    Any help would be appreciated!
    Thanks,
    -Matt

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    dont forget the qualifiers around pH test. so its
    If(DLookUp("[pH]", "[pH Test]", "[Property_FK]="& "[tbPH].[Value]","X","")

    I also dont think the Inline If has an override in Access for using it like you have. If you want to use Inline IF use
    IIf(DLookUp("[pH]", "[pH Test]", "[Property_FK]="& "[tbPH].[Value]","X","")

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your Dlookup is incorrect. You want to put a value INTO tbPH, not use it in the criteria. What text box on your form contains the search value? I'm going to assume it is tbProp, and that it is numeric.

    So, your DLookup becomes: DLookUp("[pH]", "[pH Test]", "[Property_FK]=" & [tbProp].[Value])

    Note the addition of the required square brackets around PH Test (because PH Test contains a blank)

    Adding the IIF gives you : iif(DLookUp("[pH]", "[pH Test]", "[Property_FK]=" & [tbProp].[Value]), "X", "")

    You woud use that expression as the source for the form control tbPH:

    =iif(DLookUp("[pH]", "[pH Test]", "[Property_FK]=" & [tbProp].[Value]), "X", "")

  4. #4
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    =iif(DLookUp("[pH]", "[pH Test]", "[Property_FK]=" & [tbProp].[Value]), "X", "")

    ^evaluates into an error. Which is essentially the problem. If I change [tbProp].[Value] to "[tbProp].[Value]",it evaluates but does not update with a new selection of the combobox.

    "You want to put a value INTO tbPH, not use it in the criteria. What text box on your form contains the search value? I'm going to assume it is tbProp, and that it is numeric."
    Yea, small typo on my part. It is tbProp, however the values in it are going to be text. Changing it to
    [tbProp].[Value]&"" evaluates to an error.


  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    What is the error you get?

    If tbProp is text, try this (changes in red)

    =iif(DLookUp("[pH]", "[pH Test]", "[Property_FK]='" & [tbProp].[Value] & "'" ), "X", "")
    Note this leading single quote.......................................^

    (for future reference, when you post a question, you should always show the text of any error messages you are getting)

  6. #6
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    Adding the single quotes seems to have fixed it. Thanks!

    Is there more of a detailed error description other than #Error?

  7. #7
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Code:
    Is there more of a detailed error description other than #Error?
    Unfortunately, when you get that situation, no.

    I was thinking of the error message box you get in the case of a syntax error or other run-time error.

    That #Error "value" in a form or query is one of the more frustrating problems to solve.

    Glad you got it working.

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

Similar Threads

  1. DLOOKUP in textbox on form
    By laavista in forum Access
    Replies: 6
    Last Post: 10-20-2014, 06:24 AM
  2. Textbox using dlookup for Query
    By CTdbdev in forum Forms
    Replies: 2
    Last Post: 08-04-2014, 07:45 PM
  3. Dlookup with criteria of textbox
    By thescottsman92 in forum Access
    Replies: 3
    Last Post: 08-30-2013, 03:32 AM
  4. Replies: 4
    Last Post: 05-31-2013, 07:00 PM
  5. Replies: 2
    Last Post: 04-20-2013, 03:37 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