VB code refresh on Print

jguscs

Registered User.
Local time
Today, 01:13
Joined
Jun 23, 2003
Messages
148
Is there any way I can have each record's controls refresh their conditional VB code for each record printed?
Specifically:
I have some simple VB code that conditionally hides a control in the form (depending what's in another control).
It works fluidly when browsing from record to record on-screen; however, when the form's records are printed, the conditional VB code is "skipped" leaving "un-refreshed" controls for each record/page.

I realize that, when it comes to printing, forms are less easily manupilated than reports. However, I can not add the same conditional VB code actions to controls in a report as I can in a form (can I?).

Sample Code:

Private Sub Form_Current()
If Len(Forms![My Form]![FieldA] = 0) Then
Forms![Equipment Profile]![Check100] = True
Else
Forms![My Form]![Check100] = False
End If
 
Try your conditional code in the On Print event of the detail section of your report.

Something like:

If Len(Me![FieldA]) = 0 Then
Me[Check100].Visible = True
Else
Me![Check100].Visible = False
End If


hth,
Jack
 
Right, thanks.
In the mean time, I realized that I really need to do this in a form, not a report, due to the fact that there need to be some modifyable fields for the users.
So...
Is there any way I can have a printed form pay attention to its visual basic code?
 
Sorry Jack, you need to use the Format event. Here's the help entry for the Print event.

Print Event
See Also Applies To Example Specifics
The Print event occurs after data in a report section is formatted for printing, but before the section is printed.

Remarks
To run a macro or event procedure when this event occurs, set the OnPrint property to the name of the macro or to [Event Procedure].

For a report detail section, the Print event occurs for each record in the section just before Microsoft Access prints the data in the record. A Print event procedure or macro has access to the data in the current record.

For report group headers, the Print event occurs for each new group, and a Print macro or event procedure has access to the data in the group header and the data in the first record in the detail section. For report group footers, the Print event occurs for each new group, and a Print macro or event procedure has access to the data in the group footer and the data in the last record in the detail section.

You can use the Print event to run a macro or event procedure only after Microsoft Access has prepared data for printing on a page. For example, you can calculate running page totals that are printed in the page header or footer.

For changes that affect page layout, such as displaying or hiding controls, use the Format event.

The Print event occurs only for sections that are actually printed. If you need access to data from sections that aren't printed (for example, you are keeping a running sum, but are only printing certain pages), use the Format event instead.

The Page event occurs after all the Format events for the report, and after all the Print events for a page, but before the page is actually printed.
 
Last edited:
Again, thanks Pat (conditional formatting does work in the Format event, BTW)...
Only thing is that I need to use a form, not a report.
Any ideas?
 
Pat -

DRAT! And I tried some simple code in the On Print event and it was doing what I wanted... I had originaly said either the On Print or On Format but wanted to be more specific so I did a simple test....

Thank you for pointing out my error!

JGUSCS -

I am not sure what you are doing but it sounds like you can still use a report. Just print a report based on the record the user is working with rather than all the records. I assume that if the user is working with a single record that you only want to print that record as that is all that would be printed if your printed the form. You can refer to the form in the code in your report if you need to.

LOL! Did I get this one right Pat?

Jack
 
Jack, I'm surprised that your tests worked in the Print event. I didn't test anything, I relied on help for the answer.

jguscs, conditional formatting is NOT the same thing as the Format event of a report section.

If you look up Format Event in help, you should see the Format, Print, and Retreat entries all listed.

To get to help for VBA, remember to have a VBA code window open before opening help.
 
Pat -

This is the code that I used in the On Print event and it hid the correct control and showed all others:

If Me.ReqID = 72 Then
Me.RequestDate.Visible = False
Else
Me.RequestDate.Visible = True
End If

What did I miss, IF you have the time....

Jack
 
It seems that the code works in either the Print or the Format
sub procedures.

I've pretty much given up on doing it in forms.
It works in reports, so. There.
 
You didn't miss anything. When I have needed to do this, I have used the Format event because the Print event help entry says specifically to use the Format event for this purpose. I never had any reason to question the help entry because the Format event works fine.

I would suggest that even though the conditional formtting seems to work in the Print event, that you switch to using the Format event. When a help entry is specific, as this one is, you will get no sympathy from MS when things change in the next Access version and the code will no longer work in the Print event.
 
I am glad you got it sorted and working! Continued success with your project....

With thanks to Pat for peering over my shoulder and keeping me on my toes. Thanks Pat!

Jack
 

Users who are viewing this thread

Back
Top Bottom