Discussion Locked

Parametrs in Access

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I start the same report from several forms. The user limits the report from the form via the criterion in OpenReport. How do I mention the limitation in the report header? I cannot use VB to assign to the header, because one cannot assign to that object. What I am doing is putting the parameters in a module along with functions returning the parameters, and then using those functions in an expression defining the header. This works, but is not handy. I want something neater.

3 replies

by sl-campbell

Give this a try:

In a Module put in the declarations section a Type variable:

Private Type ParamRpt
ReportName As String
Criteria As String

'HERE you can add more variables
'
'
End Type

'And the dim it as Public
Public ReportParameters As ParamRpt

'Then in the Form's code window ?n the Event proceedure for the command button that opens the report, assign something to the variable:

Private Sub cmdOpenReport_Click()
On Error GoTo Err_cmdOpenReport_ClickDim stDocName As String

ReportParameters.ReportName = "myREPORTTITLE"
ReportParameters.Criteria = "myCRITERIA"

stDocName = "myReport"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdOpenReport_Click:
Exit SubErr_cmdOpenReport_Click:
MsgBox Err.Description
Resume Exit_cmdOpenReport_Click

End Sub

'Then in the report add 2 labels, (for this example), to the report Header:
lblTitle
lblCriteria

'Then in the code window for the reportin the Report_Open event put the following code assigning variables to the label captions:

Private Sub Report_Open(Cancel As Integer)
lblCriteria.Caption = ReportParameters.Criteria
lblTitle.Caption = ReportParameters.ReportName
End Sub

'Of course there are other ways.

by shanghai sam

Visual Basic does not prompt for "Caption" on a label, but this works all the same. May you have a long life, many children and a high pension.

This discussion is closed to new replies.