Using one command button to open one of two reports

A

AccessIM

Hi -

Currently I have a form and a subform. On the form, I have a command button
that opens a report in print preview based on criteria set from information
on the subform.

My question is: Can I use the same command button to open a different
report based on a field in the subform?

For example, if the DISCIPLINE field in the selected record on the subform
says "ATTENDANCE INFORMATION FORM", I would like the
rptAttendanceInformationFormReprint to open when the button is clicked.
However, if the DISCIPLINE field in the selected record on the subform says
anything other the "ATTENDANCE INFORMATION FORM", I would like the
rptDisciplineReportReprint to open when the button is clicked.

I was thinking this could be done with an if...else statement in the
OnClick() event in VB but I am not very good at writing code and all attempts
I have made have not worked.

Any help would be appreciated! Thank you.
 
M

Marshall Barton

AccessIM said:
Currently I have a form and a subform. On the form, I have a command button
that opens a report in print preview based on criteria set from information
on the subform.

My question is: Can I use the same command button to open a different
report based on a field in the subform?

For example, if the DISCIPLINE field in the selected record on the subform
says "ATTENDANCE INFORMATION FORM", I would like the
rptAttendanceInformationFormReprint to open when the button is clicked.
However, if the DISCIPLINE field in the selected record on the subform says
anything other the "ATTENDANCE INFORMATION FORM", I would like the
rptDisciplineReportReprint to open when the button is clicked.

I was thinking this could be done with an if...else statement in the
OnClick() event in VB but I am not very good at writing code and all attempts
I have made have not worked.


Try something like:

If Me.DISCIPLINE = "ATTENDANCE INFORMATION FORM" Then
DoCmd.OpenReport "rptAttendanceInformationFormReprint",
acViewPreview
Else
DoCmd.OpenReport "rptDisciplineReportReprint",
acViewPreview
End If
 
A

AccessIM

Thank you, Marsh. Sorry about the delay in getting back. This code works but
there is still one small problem.

When there is more than one record in the subform, I have to manually select
the record that I want to use. For example, there are two records in the
subform. One has a DISCIPLINE of "ATTENDANCE INFORMATION FORM" and the
second has a DICSIPLINE of "VERBAL WARNING". I am using a Yes/No check box
called REPRINT to identify which record I want to look at. When I click the
REPRINT check box on the first record with "ATTENDANCE INFORMATION FORM", the
rptAttendanceInformationFormReprint opens which is correct.

However, if I close the report and check the REPRINT box for the second
record that has "VERBAL WARNING" as the DISCIPLINE, it opens that record
information in rptAttendanceInformationFormReprint which is the incorrect
report for this discipline. It should open rptDisciplineReportReprint.

I noticed that anytime I click a different record's REPRINT box, the record
selector on the subform stays on the first record. If I manually move the
record selector to the second record, everything works perfectly.

How can I get the record selector to move to the record that I check to
reprint?

Thank you in advance!
 
M

Marshall Barton

AccessIM said:
Thank you, Marsh. Sorry about the delay in getting back. This code works but
there is still one small problem.

When there is more than one record in the subform, I have to manually select
the record that I want to use. For example, there are two records in the
subform. One has a DISCIPLINE of "ATTENDANCE INFORMATION FORM" and the
second has a DICSIPLINE of "VERBAL WARNING". I am using a Yes/No check box
called REPRINT to identify which record I want to look at. When I click the
REPRINT check box on the first record with "ATTENDANCE INFORMATION FORM", the
rptAttendanceInformationFormReprint opens which is correct.

However, if I close the report and check the REPRINT box for the second
record that has "VERBAL WARNING" as the DISCIPLINE, it opens that record
information in rptAttendanceInformationFormReprint which is the incorrect
report for this discipline. It should open rptDisciplineReportReprint.

I noticed that anytime I click a different record's REPRINT box, the record
selector on the subform stays on the first record. If I manually move the
record selector to the second record, everything works perfectly.

How can I get the record selector to move to the record that I check to
reprint?


If the check box is in the subform's detail section, then
any click anywhere in the detail section should
automatically make that record the current record. Either
you have some other arrangement (check box not in subform's
detail section??), you have some odd code that is resetting
the current record, or your form is corrupted.

The difference between clicking the record selector and
clicking a control in the detail section is that the form's
click event is triggered instead of the control's event.
 

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