entering criteria for a query via a form

O

omas

can anyone help me in using a form to access a query but being able to enter
the criteria via a form and the resulting action should open a query based on
the criteria entered nstead of going to the query and editing it.
 
V

Van T. Dinh

You can use the full reference to the Control on the Form as the Parameter
in the Query. The SQL String of the Query should be something like:

SELECT ...
FROM ...
WHERE [YourField] = Forms!frmCriteria!txtValue

and provided that the frmCriteria is open and these exists a value in
txtValue, Access will resolve / substitute the the Parameter with the Value
in the TextBox for you when you run the Query.
 
J

John Vinson

can anyone help me in using a form to access a query but being able to enter
the criteria via a form and the resulting action should open a query based on
the criteria entered nstead of going to the query and editing it.

Set up a Form, unbound - no table or query. Let's call it frmCrit. Put
whatever controls you want to use as criteria - textboxes, combo
boxes, checkboxes, whatever. Let's say you have a table of States and
a combo box cboState, just as an example.

Your Query would have a criterion

=Forms![frmCrit]![cboState]

on the State field.

It would be convenient to create a Form (for onscreen display), or a
Report (for printing), or both, based on this query. Put a command
button on frmCrit to open the form and/or report. The user would open
frmCrit (from a switchboard perhaps), fill in the criteria, and click
the button to display the results, without ever needing to even see
the query in either design or datasheet view.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Top