Form input into query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query that works fine, but I would like to generalize it so that a form can provide the parameters for the query. I have put the "Where" criteria in the query and set the criteria to be the form object (a combo box). When I open the form, and select the criteria from the combo box, I click a button to open the query. However, the query still prompts for the value instead of reading it from the form

Any ideas

Thanks
 
A Question about the Query: -

Are you specifying your filter criteria in the Query
against the actual field?

If you are not then this is the problem. Open up the Form
and the Query, both in "Design View". For the Query, find
the field, then select the Criteria: Box underneath the
Field.

You then need to create a statement like: -
Like [Forms]![StandardFormsOfInstruction]![SiteNumber]
In the Criteria: -

[Forms] identifies the object is a Form.
[StandardFormsOfInstruction] is the name of the Form.
[SiteNumber] is the name of the Field.

Adjust the names of the objects then save and close the
Query.

For your Command Button on the Form, you will need the
following code: -

Dim QryName As String
QryName = "MyQueryToOpen" 'REPLACE MyQueryToOpen WITH THE
NAME OF YOUR QUERY
DoCmd.Close acQuery, QryName, acSaveNo
DoCmd.OpenQuery, QryName, acViewNormal,acReadOnly

HTH


Tony C.
-----Original Message-----
I have a query that works fine, but I would like to
generalize it so that a form can provide the parameters
for the query. I have put the "Where" criteria in the
query and set the criteria to be the form object (a combo
box). When I open the form, and select the criteria from
the combo box, I click a button to open the query.
However, the query still prompts for the value instead of
reading it from the form.
 
I have a query that works fine, but I would like to generalize it so that a form can provide the parameters for the query. I have put the "Where" criteria in the query and set the criteria to be the form object (a combo box). When I open the form, and select the criteria from the combo box, I click a button to open the query. However, the query still prompts for the value instead of reading it from the form.

Any ideas?

Thanks

Please post the SQL view of the query and the code in your button's
Click event. No way to tell what's wrong without knowing exactly what
you're in fact doing!
 
Back
Top