Results 1 to 3 of 3
  1. #1
    Zholt is offline Novice
    Windows Vista Access 2003
    Join Date
    May 2009
    Posts
    6

    Use form data in a query

    Hi guys, Please could somebody show me how to use the data entered in a form, to be the criteria in a query?

    Regards Zac

  2. #2
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    Let's say that you enter a value in a textbox on your form (fmYourFormName), and that the name of this textbox is 'txtYourTextBox'.

    Then, you would put the following in the criteria row of the relevant query field:
    Code:
    [Forms]![fmYourFormName]![txtYourTextBox]
    Now, that works if your text box is on a regular form, but it will not work if the textbox is on a subform. For that, you need to tell Access both the form name, AND tell it to reference the subform.

    But to properly understand this, you need to understand a little more about subforms.

    When you place a subform on a form you are actually placing a subform control onto the form: not the form that you see within that subform control. In a sense, this subform control is just a container.

    Within this container, there is a source object property which refers to the actual form which becomes the subform.

    So, how does this relate to a parameter query?

    When you use a subform control as a parameter for your query you will need to specify the container name, and then specify the name of the control on the form object within the container.
    eg
    Code:
    [Forms]![fmYourFormName]![SubformContainerNameHere].Form![txtYourTextBox]
    Hope that helps.

  3. #3
    euoberts is offline Novice
    Windows Vista Access 2003
    Join Date
    May 2009
    Posts
    1
    Quote Originally Posted by CraigDolphin View Post
    Let's say that you enter a value in a textbox on your form (fmYourFormName), and that the name of this textbox is 'txtYourTextBox'.

    Then, you would put the following in the criteria row of the relevant query field:
    Code:
    [Forms]![fmYourFormName]![txtYourTextBox]
    Now, that works if your text box is on a regular form, but it will not work if the textbox is on a subform. For that, you need to tell Access both the form name, AND tell it to reference the subform.

    But to properly understand this, you need to understand a little more about subforms.

    When you place a subform on a form you are actually placing a subform control onto the form: not the form that you see within that subform control. In a sense, this subform control is just a container.

    Within this container, there is a source object property which refers to the actual form which becomes the subform.

    So, how does this relate to a parameter query?

    When you use a subform control as a parameter for your query you will need to specify the container name, and then specify the name of the control on the form object within the container.
    eg
    Code:
    [Forms]![fmYourFormName]![SubformContainerNameHere].Form![txtYourTextBox]
    Hope that helps.
    I have a similar issue. I can get a query to work properly when launching from the main db window (with the form open in another window) with the
    Code:
    [Forms]![fmYourFormName]![dropdown].[text]
    as criteria for a field. However, if I add a button in the form containing the dropdown to launch the form, it doesn't work. I tried 'printing' the value to the query to see what WAS being passed, and it seems nothing at all is. Anyone know why this might be?

    Thanks in advance

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

Similar Threads

  1. Replies: 2
    Last Post: 11-25-2013, 10:56 AM
  2. Replies: 9
    Last Post: 03-24-2009, 09:19 PM
  3. Form does not accept data
    By bongo in forum Forms
    Replies: 3
    Last Post: 03-14-2009, 01:52 AM
  4. data query question
    By mrayray09 in forum Queries
    Replies: 0
    Last Post: 01-20-2009, 08:41 AM
  5. Replies: 0
    Last Post: 11-12-2008, 05:18 PM

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