Openargs not being populated (1 Viewer)

GoodyGoody

Registered User.
Local time
Today, 02:26
Joined
Aug 31, 2019
Messages
104
I have some VBA code:

Code:
DoCmd.OpenReport strReportName, acPreview, , , , "TESTING"
but when I inspect me.openargs in the report Load or Open event Me.Openargs shows as null. What am earth am i doing wrong?
 

June7

AWF VIP
Local time
Yesterday, 17:26
Joined
Mar 9, 2014
Messages
3,141
Works for me.

Post your code from report.
 

Micron

AWF VIP
Local time
Yesterday, 21:26
Joined
Oct 20, 2018
Messages
3,211
...and make sure you are not opening the report from design view. Switching views is not the same as invoking the DoCmd method.
 

GoodyGoody

Registered User.
Local time
Today, 02:26
Joined
Aug 31, 2019
Messages
104
Code from the Report Open event. I notice that the report Load event is not firing. I put a break point in there but it doesn't fire. Is that a clue as to what is wrong?

Code:
Private Sub Report_Open(Cancel As Integer)
Dim intControlCount As Integer
Dim varOpenArgs As Variant

varOpenArgs = Me.OpenArgs
intControlCount = Nz(Me.OpenArgs, 0)
End Sub
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:26
Joined
Jul 9, 2003
Messages
11,677
I find the openargs method, the method of passing lots of information in a string, separated by delimiters and passing them through with the openargs to be quite a challenging method of handling data. I find the method explained in this video:-

Pass Info In to a Report - Nifty Access


A method that makes the data available in the "Calling Form" the form that is Opening the Report, then the Report is directed to extract the necessary information from the "Calling Form". With this method you have a much higher degree of control over the information, it's logical. It's easy if you need to add or remove information.

More information in a Blog on the Nifty Access website here:-

https://www.niftyaccess.com/pass-info-in-to-a-report/

This is the Code used in the video:-

Here is the VBA Code for this Method
Code:
'======================== this code in the Form ======================
Option Compare Database
Option Explicit

Private mstrRptHeaderLabel As String
Private mstrRptSQL As String

'<<<<<<<<<<<<<< --- PROPERTY STATEMENTS --- >>>>>>>>>
Property Let prpRptHeaderLabel(strHeader As String)
    mstrRptHeaderLabel = strHeader
End Property      'prpRptHeaderLabel Let

Property Get prpRptHeaderLabel() As String
    prpRptHeaderLabel = mstrRptHeaderLabel
End Property      'prpRptHeaderLabel Get

Property Get prpRptSQL() As String
    prpRptSQL = mstrRptSQL
End Property      'prpRptSQL Get

Property Let prpRptSQL(strHeader As String)
    mstrRptSQL = strHeader
End Property      'prpRptSQL Let

Private Sub btnOpenRport_Click()
Me.prpRptSQL = "SELECT ID, T1, T2, T3, T4 FROM Table1 WHERE (((T3)='ww'))"
Me.prpRptHeaderLabel = "REPORT HEADER FROM FORM"

        Dim strRptName As String
        strRptName = "rptTable1"
           
           DoCmd.OpenReport strRptName, acViewReport, , , , Me.Name
                With Reports(strRptName)
                   .Caption = "I CAN CHANGE THE CAPTION"
                End With

End Sub
'======================== this code in the Form ======================

'======================== this code in the Report ======================
Option Compare Database
Option Explicit

Private Sub Report_Open(Cancel As Integer)
    If Len(Me.OpenArgs) > 0 Then
        With Forms(Me.OpenArgs)
            Me.RecordSource = .prpRptSQL
            Me.lblRptHeader.Caption = .prpRptHeaderLabel
            Me.lblShowSQL.Caption = .prpRptSQL
        End With
    End If
End Sub
'======================== this code in the Report ======================
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 21:26
Joined
Feb 19, 2002
Messages
29,027
You are passing a string. Where is the integer value coming from?
 

GoodyGoody

Registered User.
Local time
Today, 02:26
Joined
Aug 31, 2019
Messages
104
Sorry it's been a while. I haven't been able to access the forum for over a week. It just kept crashing on me with 'Database error'. Thanks. That was just testing. The issue was that I was preprocessing the report for a crosstab query and it had been put in design mode. Having done the adjustments on the column data for the crosstab report I called the report in Preview mode but hadn't closed it beforehand so it was still in design mode and therefore not passing OpenArgs. Thanks for getting back though
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom