Open report without printing

ClaraBarton

Registered User.
Local time
Today, 00:01
Joined
Oct 14, 2019
Messages
709
@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.
 
The report immediately starts printing and does not hit the Open code in the report.
Put a stop in the code in the Open event so we can be sure the event is not triggered. And also check the value of the filter if the code is triggered.
 
Nevermind. I found another piece that works I can send my record source from the form and place the code after the open event. Thank you for your help.
 
Well, please show the code (within code tags). You never know, someone else might want to do it that way?
 
Nevermind. I found another piece that works I can send my record source from the form and place the code after the open event. Thank you for your help.
So, did you do what I suggested? Did you determine that the Open event is actually running? If you didn't stop the code there as I suggested and check the filter you are trying to use, you don't actually know what the problem was or that the variables are properly set in order to skip the appropriate number of labels.
 
I do this in my db. Report is saved without a RecordSource. Code in report Open event sets RecordSource. Going direct to print output, it has the expected data even though does not hit breakpoint in the event.
 
I do this in my db. Report is saved without a RecordSource. Code in report Open event sets RecordSource. Going direct to print output, it has the expected data even though does not hit breakpoint in the event.
That sounds very strange. In this particular case though the Open event was doing TWO things.
1. setting the RecordSource
2. populating variables that are used to skip labels

It seemed to have the correct values to skip the number of labels (unless she didn't bother to mention that error) but the filter wasn't working. The OP didn't bother to try my suggestion though so she'll never know what was wrong,

I generally use queries with parameters so I don't have to change the RecordSource when the form opens.
 

Users who are viewing this thread

Back
Top Bottom