Help with multiple criteria Macro

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

Guest

I have a form that allows users to input selected criteria which will
determine which report will be run when the submit button is clicked. The
form has three fields - first name, last name, and category. The user must
select either first name AND last name or category. The report will then
generate off the criteria and either return a single name or a list of names
in a particular category. From this report, the user will then print mailing
labels.

Any help would be greatly appreciated.

Thanks.
 
if isnull(firstname) and isnull(lastname) and not isnull(catagory) then
...... run catagory report
else not isnull(firstname) and not isnull(lastname) and
isnull(catagory) then
...... run name report
else
msgbox "Incorrect criteria has been entered." & chr(13) & " Enter
First and Last Name only or" & chr(13) & " Enter only catagory."
endif


Watch for workwrap on this posting.......
 
Risikio,

If I understand you correctly, the easiest way to do this is by
referencing the form controls in the Criteria of the query that the
report is based on.

For example, in the design view of the query, in the first criteria row,
put this under the Category column...
Is Null
.... and in the First Name and Last Name columns, the equivalent of this...
[Forms]![NameOfForm]![First Name]
[Forms]![NameOfForm]![Last Name]
Then, in the second criteria row, the reverse, i.e. in the First Name
and Last Name columns:
Is Null
.... and in the Category column
[Forms]![NameOfForm]![Category]

If you want to check that the user has entered the correct criteria, you
can do this in the Conditions column of the macro design.
 
Thanks, Steve. This is exactly what I needed.

Steve Schapel said:
Risikio,

If I understand you correctly, the easiest way to do this is by
referencing the form controls in the Criteria of the query that the
report is based on.

For example, in the design view of the query, in the first criteria row,
put this under the Category column...
Is Null
.... and in the First Name and Last Name columns, the equivalent of this...
[Forms]![NameOfForm]![First Name]
[Forms]![NameOfForm]![Last Name]
Then, in the second criteria row, the reverse, i.e. in the First Name
and Last Name columns:
Is Null
.... and in the Category column
[Forms]![NameOfForm]![Category]

If you want to check that the user has entered the correct criteria, you
can do this in the Conditions column of the macro design.

--
Steve Schapel, Microsoft Access MVP
I have a form that allows users to input selected criteria which will
determine which report will be run when the submit button is clicked. The
form has three fields - first name, last name, and category. The user must
select either first name AND last name or category. The report will then
generate off the criteria and either return a single name or a list of names
in a particular category. From this report, the user will then print mailing
labels.

Any help would be greatly appreciated.

Thanks.
 
Back
Top