General discussion

Locked

Parametrs in Access

By john_wills ·
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.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Parametrs in Access

by sl-campbell In reply to Parametrs in Access

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.

Collapse -

Parametrs in Access

by Shanghai Sam In reply to Parametrs in Access

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.

Collapse -

Parametrs in Access

by john_wills In reply to Parametrs in Access

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums