I want to enter a parameters (ex. date range), then to click on a command "Execute Query" (All of them are available on form header) to run a query on a form detail.
kindly see attached Pic.
Thank you @jdraw, I knows how to set a parameter in query, but I want to run the query ( after entering the parameters) and to show the results in the form detail
Perhaps you can provide more detail and some sample data to ensure we're talking about the same thing.
Seems you have a form with some controls. You enter some values into the controls and click a button. Behind the scene the control values are part of query criteria that requests some info from your underlying table(s); and the result of the query is placed on your form or a subform on that form.
These may be helpful.
1:
Thank you @jdraw, I knows how to set a parameter in query, but I want to run the query ( after entering the parameters) and to show the results in the form detail
Make the query bound to the form reference the unbound form fields with the criteria:
Select ... From ...
Where (fld1 = Forms!myform!cbofld1 OR Forms!myform!cbofld1 Is Null) AND (fld2 = Forms!myform!cbofld2 OR Forms!myform!cbofld2 Is Null)
The form will open up empty. The user chooses something from either or both unbound combos and presses the "run" button. The code behind the "run" button is simply:
Me.Requery
Pay attention to the parentheses in the example if you want to use multiple criteria fields and you want them to be optional. The parentheses create two conditions that will be and'd
Make the query bound to the form reference the unbound form fields with the criteria:
Select ... From ...
Where (fld1 = Forms!myform!cbofld1 OR Forms!myform!cbofld1 Is Null) AND (fld2 = Forms!myform!cbofld2 OR Forms!myform!cbofld2 Is Null)
The form will open up empty. The user chooses something from either or both unbound combos and presses the "run" button. The code behind the "run" button is simply:
Me.Requery
Pay attention to the parentheses in the example if you want to use multiple criteria fields and you want them to be optional. The parentheses create two conditions that will be and'd
Thank you @Pat Hartman;
I have tried your solution, but the query results will not be displayed on the form detail; I attached a picture from the database, it may help to explain my post.
It's very important to display the query result on "Form Detail", because I need to select some of the students (from the query result) to send an Email for them
Thank you @Pat Hartman, you've described the perfect solution.
Since I'm not a programmer , I thought that if I connect the parameter inside query in "Criteria" OR by writing VBA code inside the form, I will got the same results.