Results 1 to 7 of 7
  1. #1
    dnjtdjq is offline Novice
    Windows 7 32bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    4

    Using Dlookup in Subform

    I'm a beginner in Access and I'm not sure if what I want to do is correct or possible to do in Access but I will give it a go.

    Im trying to make a recipe template using Access Form and I have three tables I first made.

    Combined Table, Ingredients Table and Recipe Table.

    In Ingredients Table, I have 3 fields which are Ingredients ID, Ingredient and price.

    In Combined Table, I have Recipe ID, Ingredients, Price, Amount and Total

    When I made a Form, I have put Recipe Table as a main form and Combined table as a subform.

    Then, in subform I have deleted Recipe ID.

    What I want to do is the price field in subform to be auotmatically fileld if when I type Ingredients in subform ingredients field.

    The dlookup formula I used in the control source of a combo box is =DLookUp("Price","Ingredients Table","Ingredient=" & [Ingredient Combo])

    And no matter how I change the formula, the end result is #ERROR.

    I have attached the screenshot of what I did so hopefully this would help.

    ThanksClick image for larger version. 

Name:	Capture.PNG 
Views:	22 
Size:	98.4 KB 
ID:	27921

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    IMHO it would be better to include the price field as a column in the Ingredients combo box and reference that column in an expression used as the Control Source property of the Price textbox control.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    I agree with Bob - but a reason your dlookup fails is because you have spaces in your table name - spaces mean you have to surround the name with square brackets -"[Ingredients Table]".

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Quote Originally Posted by Ajax View Post
    I agree with Bob - but a reason your dlookup fails is because you have spaces in your table name - spaces mean you have to surround the name with square brackets -"[Ingredients Table]".
    Might also be because Ingredients combo box is bound to Ingredients ID field rather than the Ingredient field.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    dnjtdjq is offline Novice
    Windows 7 32bit Access 2013 64bit
    Join Date
    Mar 2017
    Posts
    4
    Quote Originally Posted by Bob Fitz View Post
    IMHO it would be better to include the price field as a column in the Ingredients combo box and reference that column in an expression used as the Control Source property of the Price textbox control.
    Thanks Bob,
    I'm quite lost on how I can do what you say.
    Could you please explain a bit more so I can follow what you just said.

    Thank you

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Can you show us the sql statement used in combo box and tell us the name of the price field in the ingredients table

  7. #7
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793

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

Similar Threads

  1. Trouble with DLookup on Subform
    By GregShah in forum Forms
    Replies: 13
    Last Post: 12-14-2016, 12:41 AM
  2. Trouble with DLOOKUP in a Subform
    By Mubashir sabir in forum Forms
    Replies: 2
    Last Post: 08-21-2015, 01:38 PM
  3. Dlookup not working in Subform
    By keiath in forum Forms
    Replies: 1
    Last Post: 04-23-2014, 09:03 AM
  4. Replies: 15
    Last Post: 12-03-2010, 10:14 AM
  5. Subform Dlookup
    By jbedward in forum Forms
    Replies: 7
    Last Post: 01-13-2010, 08:06 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