For the past two days I have been working with MS Access to create an application. One of the features I wanted to create, was a parametric query that would take the value from a combobox on a form and create a report.
To be more precise I had a form with a combobox populate with IDs and names and when the user selected a specific item from the combo and clicked on a button I wanted to have a report that showed some information of related to the selected ID.
One way to do it is to create some vb code and create a select query with a “where” clause. But, that is not too flexible, caz if I want to change the query, I have to change the code.
Today I came across a more flexible solution. Parametric queries. I knew how to use parametric queries, but not in conjunction with forms. So if you want to create a parametric query related to a form, all you have to do in the query is define the parameter at the beginning like:
PARAMETERS [Forms]![formName]![ControlName] ParameterType;
In the where clause you also have to use the same notation. So for example:
where Id = [Forms]![formName]![ControlName]
and that’s it!