I have a Microsoft Access 2010 form with dropboxes and a checkbox which represent certain parameters. I need to run a query with conditions based on these parameters. It should also be a possibility for no criteria from the dropdown boxes and checkbox in order to pull all data.
I have two working ways of implementing this:
I build a query with
IIf
statements in theWHERE
clause, nesting statements until I have accounted for every combination of criteria. I reference the criteria in the SQL logic by usingForms!frmMyFrm!checkbox1
for example or by using a functionFormFieldValue(formName,fieldName)
which returns the value of a control with the input of the form and control name (This is because of previous issues). I set this query to run with the press of the form's button.I set a vba sub to run with the press of the button. I check the conditions and set the query SQL to a predetermined SQL string based on the control criteria (referenced in the same way as the previous method). This also involves many
If...Else
statements, but is a little easier to read than a giant query.
What is the preferred method? Which is more efficient?