Open report without printing

ClaraBarton

Registered User.
Local time
Today, 06:47
Joined
Oct 14, 2019
Messages
708
@Pat Hartman
I'm trying to use Pat's label printing code. When I open the report from a form I use
Code:
DoCmd.OpenReport strReport, acViewNormal, _
                OpenArgs:=Me.Name & "|" & Skip

The report immediately starts printing and does not hit the Open code in the report.
Code:
    Private CallingForm         As String
    Dim intBlankCount           As Integer
    Dim Skip                    As Integer

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If intBlankCount < Skip Then
       Me.NextRecord = False
       Me.PrintSection = False
       intBlankCount = intBlankCount + 1
    End If
End Sub

Private Sub Report_Open(Cancel As Integer)
 Dim strFilter               As String
strFilter = Forms.frmUtility.fsubUtility.Form.Filter
    If Not IsNull(Me.OpenArgs) Then
           CallingForm = Left(OpenArgs, InStr(OpenArgs, "|") - 1)
        Skip = Mid(OpenArgs, InStr(OpenArgs, "|") + 1)
    End If
    Me.RecordSource = "qryUtility Where " & strFilter
    Me.CurrentView = 5
End Sub
 
acViewNormal selects that you open the report in "normal" view - which is equivalent to PrintPreview - and then it triggers the output of the report to go to the printer.

Use either acViewReport or acViewPreview, which does not trigger forwarding the report to the printer.
 
Then I receive a "the property is read only and cannot be set" at Me.Recordsource =...
 
To view a report and not print, I think you could use either acViewPreview or acPreview.
 
Yes, I know. But you can't change the record source. Which it has no record source because I want to establish it in the opening of the report.
 
Yes, I know. But you can't change the record source. Which it has no record source because I want to establish it in the opening of the report.
I would change the SQL of a saved query in code just prior to opening the reportUrey would be the record source of the report and would filter as desired
 
The fly in the ointment of changing the report's recordset is that Access "diddles" with the initial recordset because it has to tailor the query based on your design choices for sorting and grouping. The initial recordset gets modified so much that Access creates a "shadow query" to generate the required recordset, totally without regard to the ORDER BY and GROUP BY clauses you might have had in the original design.

Forms don't do this - but reports do. Therefore, an on-the-fly design for reports is going to not work very nicely at all.
 
I need this to skip used labels. Maybe I should go back to creating a table before printing. This seemed so much more smoother...
 
There are various ways you can control whether to use the acPrintPreview Constant for the OpenReport method's View argument, e.g. a check box or option group on the calling form, on the value of which you can conditionally execute the appropriate code. Simplest of all is to have separate Print and Preview buttons on the form. The demo file I attached to my reply in your earlier thread does this.
 

Users who are viewing this thread

Back
Top Bottom