Results 1 to 4 of 4
  1. #1
    bener is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2011
    Posts
    4

    Question Using form fields as query criteria


    Hi
    I need to limit the population displayed in a combo box to only those records that one of their fields match a field already entered in the current form (but not yet saved to the database).
    In a food catering application I have a menu table with dish ID, dish name and dish category. In an order from, the user first selects a category and then selects a specific dish. I would like to populate the dish selection combo with only the dishes having the preselected category.
    I didn't find a way to refer to fields of the current form in the query selection criteria. Can this only be done using VBA?
    Thanks

  2. #2
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    You can refer to the form in the query criteria. Try using =[Forms]![Form Name]![Field Name] in the criteria of your field...

  3. #3
    bener is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2011
    Posts
    4
    Quote Originally Posted by Stingaway View Post
    You can refer to the form in the query criteria. Try using =[Forms]![Form Name]![Field Name] in the criteria of your field...
    Thanks. I did just that. What happens is that the value of the field seems to be read only once at the first use of the combo. Suppose I entered "1" in the creteria field and then activated the combo - I get a correct list filtered according to this value. However if I then change the value of the field, even after moving to the next record, I still get the list using "1" as selection criteria.
    See sample DB enclosed

  4. #4
    alansidman's Avatar
    alansidman is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,529
    You need to clear the combo box. Put a command button on your form that has the combo box. In the on click event for the command button type this:

    Code:
    me.comboboxname.value = " "
    me.requery
    In the afterupdate event for the combo box type:

    Code:
    me.requery
    Alan

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

Similar Threads

  1. Query criteria fields flooded after search
    By a12ctic in forum Queries
    Replies: 1
    Last Post: 06-27-2011, 06:25 PM
  2. Passing form fields criteria to a Query
    By yosik20 in forum Queries
    Replies: 1
    Last Post: 05-12-2011, 04:24 AM
  3. Search By Criteria - Flexible Criteria Fields
    By lilanngel in forum Access
    Replies: 0
    Last Post: 03-16-2011, 06:25 PM
  4. Replies: 2
    Last Post: 07-01-2010, 02:53 PM
  5. Yes/No Fields and Criteria in a Query
    By omicronkappa278 in forum Access
    Replies: 1
    Last Post: 05-22-2009, 09:51 AM

Tags for this Thread

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