Pass Info In to a Report

Passing Information to a Report

Often, I see examples where people pass information between Forms and Reports using Opening Arguments “openArgs” … I did this myself until I happened upon an article, I think it was from “Smart Access” which explained a very satisfying way of Passing information around.

The method still employs Opening Arguments “openArgs” but instead of using the “openArgs” to pass data, it is used to pass the Form Name, the name of the Form from where the data originates, and of course it will also be the form Opening the Report. With the Form name now in the Report, the Report knows where to look for the information it needs.

Pass Info In to a Report

Pass Info In to a Report

Video 1 (3:41)

The open-args method, the method of passing lots of information in a string, separated by delimiters and passing them through with the openargs, it’s quite a challenging method of handling data.

The method explained in this video is far superior. This method makes the data available in the “Calling Form” the Form that is Opening the Report. The Report is directed to extract the necessary information from the “Calling Form”.

With this method you have a greater degree of control over the information. It’s logical, it’s easy, especially if you need to add or remove information.

Video 1 (3:41)

Nifty Access YouTube Thumb Nail

This is in Answer to a Question on AWF

… …

Passing Information to a Report - The FORM 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 ======================
				
			

Passing Information to a Report - The REPORT CODE

				
					'======================== 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 ======================
				
			

More Useful Stuff HERE:-

Nifty Container

Nifty Container

The “Nifty Container” offers you a graphical way of managing the controls on your form. All you do is surround a group of controls with a box, choose one of the coding examples, or write your own, and there you go, you have a simple and easy-to-use method, which avoids using your Control(s) Tag Property, (the usual method of doing this) which you might well want to use for something else. There are many ways to identify controls on your form for particular attention. This “Nifty Container” idea I have developed is unique, I haven’t come across it anywhere else. All you do is draw a box around the group of controls you want to handle. You might want to make sure that the controls have text entries, you might want to make sure that at least one of the controls has an entry, anything you want to do to a group of controls can be done with the “Nifty Container” system, and at the same time avoids using the controls Tag property…

Nifty Container - Demo

Nifty Container - Demo

Video 1 (5:08)

Well here it is! Another drop in component from Nifty Access. The “Nifty Container” provides an alternative way to handle a “Block of Controls” on your form. Instead of using the “Tag Property”. This method utilizes a simple rectangle as a Container to surround a bunch of controls. Call the code and it will cycle through the objects within the rectangle and alter them to your specific programming requirements.

Video 1 (5:08)

Nifty Access YouTube Thumb Nail

… …

More Useful Stuff HERE:-

This website uses third-party software - WordPress Add-Ins to be exact. I don't know what any individual add-in does, but I'm sure that many of them collect information about you. So be aware, if you continue using this site, then you are likely to be sharing your information. I don't know how to disable this sharing for any, or all of the plugins for individual users. So I can't stop the sharing of information. If this worries you then please do not use this site... If you continue to use this site I will assume that you are happy with it.

Do you need a hand in the right direction?

You are in the right place.