Print exactly what is on form

M

Miranda

I have a report set up to print a form. Everything seems to work ok except
that my form has fields that are hidden when not needed. When I run my
report, it always shows the same fields which are not necessarily the ones
that are visible on my form. Please help!
 
D

Duane Hookom

This might not be what you want to hear but I never print forms. I always
create reports for printing. You can save a form as a report and then make
modifications.
 
M

Miranda

I am so sorry, I didn't clarify well enough. I have done just that and saved
my form and sub form as a report and subreport. They look identical to my
form with the same set up. My form has code behind it to tell each field to
be hidden or visible depending on what is chosen. I have my report set up to
print only the record that is showing when the print button is clicked. My
problem is that what shows up on the report is not what is visible on the
form. Some of the fields that are hidden on that record in the form are
visible on the report and some of the fields that are visible on that record
in the form are not visible on the report. How do I pass this code to the
report?
 
M

Maurice

It depends on the setup of the report. The detailsection of the report is an
repeating section. But if it is exactly as the form you could use something
like:

I'm assuming the fields that need to be hidden are 'known' fields, in other
words they are designated.

Report open:
if isnull(me.fieldname) or me.fieldname="" then
me.fieldname.visible=false
end if
(where fieldname is the control on the report)

And ofcourse you would have to check all your fields. In essence you could
use the same code as used on the form.

A loop through the controls could be a shortcut on this one.

Maurice
 
F

fredg

I am so sorry, I didn't clarify well enough. I have done just that and saved
my form and sub form as a report and subreport. They look identical to my
form with the same set up. My form has code behind it to tell each field to
be hidden or visible depending on what is chosen. I have my report set up to
print only the record that is showing when the print button is clicked. My
problem is that what shows up on the report is not what is visible on the
form. Some of the fields that are hidden on that record in the form are
visible on the report and some of the fields that are visible on that record
in the form are not visible on the report. How do I pass this code to the
report?

Code the Format event of whatever section in the report these possibly
hidden controls are in (i.e. the Detail Format event):

Me![ControlName].Visible = forms!FormName!ControlName.Visible

Do the same for each additional control in the report.
Note: The form must be open when the report is run.
 
M

Miranda

You have all been a great help! Thanks for the quick replies!
I have come up with this code, but am getting an error. Any help?
Run-time error 438
Object doesn't support this property or method.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_Detail_Format

Dim ctl As Control

For Each ctl In Me.Controls
Me(ctl.Name).Visible = Forms!frmBOL!sfrmData.Form!(ctl.Name).Visible

Next ctl

Exit_Detail_Format:
Exit Sub

Err_Detail_Format:
MsgBox Err.Desctiption
Resume Exit_Detail_Format
End Sub
--
Miranda


fredg said:
I am so sorry, I didn't clarify well enough. I have done just that and saved
my form and sub form as a report and subreport. They look identical to my
form with the same set up. My form has code behind it to tell each field to
be hidden or visible depending on what is chosen. I have my report set up to
print only the record that is showing when the print button is clicked. My
problem is that what shows up on the report is not what is visible on the
form. Some of the fields that are hidden on that record in the form are
visible on the report and some of the fields that are visible on that record
in the form are not visible on the report. How do I pass this code to the
report?

Code the Format event of whatever section in the report these possibly
hidden controls are in (i.e. the Detail Format event):

Me![ControlName].Visible = forms!FormName!ControlName.Visible

Do the same for each additional control in the report.
Note: The form must be open when the report is run.
 
M

Maurice

Miranda,

Don not refer to me.ctl because there is no me in that respect

For Each ctl In Me.Controls
ctl.visible=Forms!frmBOL!sfrmData.Form!(ctl.Name).Visible
end if
Next ctl


--
Maurice Ausum


Miranda said:
You have all been a great help! Thanks for the quick replies!
I have come up with this code, but am getting an error. Any help?
Run-time error 438
Object doesn't support this property or method.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
On Error GoTo Err_Detail_Format

Dim ctl As Control

For Each ctl In Me.Controls
Me(ctl.Name).Visible = Forms!frmBOL!sfrmData.Form!(ctl.Name).Visible

Next ctl

Exit_Detail_Format:
Exit Sub

Err_Detail_Format:
MsgBox Err.Desctiption
Resume Exit_Detail_Format
End Sub
--
Miranda


fredg said:
I am so sorry, I didn't clarify well enough. I have done just that and saved
my form and sub form as a report and subreport. They look identical to my
form with the same set up. My form has code behind it to tell each field to
be hidden or visible depending on what is chosen. I have my report set up to
print only the record that is showing when the print button is clicked. My
problem is that what shows up on the report is not what is visible on the
form. Some of the fields that are hidden on that record in the form are
visible on the report and some of the fields that are visible on that record
in the form are not visible on the report. How do I pass this code to the
report?

Code the Format event of whatever section in the report these possibly
hidden controls are in (i.e. the Detail Format event):

Me![ControlName].Visible = forms!FormName!ControlName.Visible

Do the same for each additional control in the report.
Note: The form must be open when the report is run.
 

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