Link Report to Form

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

Guest

Hello,
I have linked a report to a field on a form using a macro on a control
button. I don't want the report to open if there is not any data to print,
however, currently the report is opening even if there is no data to print
and the fields just contain #Error. Any suggestions?

Thanks,
Angela
 
To prevent the form opening if it has no data, use its Has Data event. Use
code or a macro to cancel the event. The event only fires if there is no
data.

If you are opening the report with OpenReport code, trap and ignore error
2501.

The calculated controls show #Error when the report has no data. If you want
to blank report to open instead of cancelling it, you can test the report's
HasData property in these controls. For example, if you have a text box with
Control Source of:
=[FirstName] & " " & [Surname]
change it to:
=IIf([Report].[HasData], [FirstName] & " " & [Surname], Null)
 
Hi Allen,
Thank you for your response. I did try the cancel event on the macro, and
the report still fires. Do you think I should use a condition on the cancel
event? Do you know if I can use a Has Data type formula as a condition on the
cancel event?

Thanks,

Allen Browne said:
To prevent the form opening if it has no data, use its Has Data event. Use
code or a macro to cancel the event. The event only fires if there is no
data.

If you are opening the report with OpenReport code, trap and ignore error
2501.

The calculated controls show #Error when the report has no data. If you want
to blank report to open instead of cancelling it, you can test the report's
HasData property in these controls. For example, if you have a text box with
Control Source of:
=[FirstName] & " " & [Surname]
change it to:
=IIf([Report].[HasData], [FirstName] & " " & [Surname], Null)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Angela said:
Hello,
I have linked a report to a field on a form using a macro on a control
button. I don't want the report to open if there is not any data to print,
however, currently the report is opening even if there is no data to print
and the fields just contain #Error. Any suggestions?

Thanks,
Angela
 
1. Create a macro that has one action: Cancel Event.

2. Save the macro with a name such as "macCancelEvent".

3. Open the report in design view, and set the On No Data property to:
macCancelEvent

No condition is needed. As previously explained, Access only fires the event
if the report has no data.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Angela said:
Hi Allen,
Thank you for your response. I did try the cancel event on the macro, and
the report still fires. Do you think I should use a condition on the
cancel
event? Do you know if I can use a Has Data type formula as a condition on
the
cancel event?

Thanks,

Allen Browne said:
To prevent the form opening if it has no data, use its Has Data event.
Use
code or a macro to cancel the event. The event only fires if there is no
data.

If you are opening the report with OpenReport code, trap and ignore error
2501.

The calculated controls show #Error when the report has no data. If you
want
to blank report to open instead of cancelling it, you can test the
report's
HasData property in these controls. For example, if you have a text box
with
Control Source of:
=[FirstName] & " " & [Surname]
change it to:
=IIf([Report].[HasData], [FirstName] & " " & [Surname], Null)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Angela said:
Hello,
I have linked a report to a field on a form using a macro on a control
button. I don't want the report to open if there is not any data to
print,
however, currently the report is opening even if there is no data to
print
and the fields just contain #Error. Any suggestions?
 
YES. This worked perfectly. Thank you very much.

Allen Browne said:
1. Create a macro that has one action: Cancel Event.

2. Save the macro with a name such as "macCancelEvent".

3. Open the report in design view, and set the On No Data property to:
macCancelEvent

No condition is needed. As previously explained, Access only fires the event
if the report has no data.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Angela said:
Hi Allen,
Thank you for your response. I did try the cancel event on the macro, and
the report still fires. Do you think I should use a condition on the
cancel
event? Do you know if I can use a Has Data type formula as a condition on
the
cancel event?

Thanks,

Allen Browne said:
To prevent the form opening if it has no data, use its Has Data event.
Use
code or a macro to cancel the event. The event only fires if there is no
data.

If you are opening the report with OpenReport code, trap and ignore error
2501.

The calculated controls show #Error when the report has no data. If you
want
to blank report to open instead of cancelling it, you can test the
report's
HasData property in these controls. For example, if you have a text box
with
Control Source of:
=[FirstName] & " " & [Surname]
change it to:
=IIf([Report].[HasData], [FirstName] & " " & [Surname], Null)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hello,
I have linked a report to a field on a form using a macro on a control
button. I don't want the report to open if there is not any data to
print,
however, currently the report is opening even if there is no data to
print
and the fields just contain #Error. Any suggestions?
 
Back
Top