Help with multiple criteria Macro

R

Risikio

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.
 
R

Ron2006

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.......
 
S

Steve Schapel

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.
 
R

Risikio

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top