I have a report that I start from a cmd button in preview mode. If I then print the report, I may get different results from what the preview screen showed.
The report runs some vb code started from the detail on format and on print events. There are also sub-reports that do the same. The code that gets called from these events, sets the visible property to false for controls that are empty (code courtesy of Steveb and 1William).
Public Function ControlDisplay(rpt As Access.Report)
Dim ctl As Control
Dim stTest As String, stTest1 As String
On Error Resume Next 'not all controls will have datasource (line for example)
For Each ctl In rpt.Section(acDetail).Controls
ctl.Visible = (Len(ctl.Value & vbNullString) > 0)
It seems that if, on a sub-report, there are 2 records and the first record has all controls populated but the 2nd record doesn't have all controls populated, that the all the controls/labels get printed anyway. It's wierd because the first time you preview then print, the empty controls print, but if you preview/print again, it's ok.
ps, I did a work around, and have separate print and preview command buttons, which seems to be working ok.