I need to create a report parameter screen

S

SRussell

Can you make the same form be the front end to a few reports? If so how do
I set this up.

I have 3 reports that need to have all or 1 customer, from start date to end
date, and a few other limiters for the SQL to reduce the # of rows or the
sorting/grouping for how the data will show.

I see myself making a different report by grouping needs. So how do I call
the proper report depending on the selection the use makes?

TIA

__Stephen
 
G

Guest

Stephen:

The following does it by setting the Filter property of a report to restrict
it by LastName in its Open event procedure, but it could be equally well use
a query with parameters as the report's RecirdSource:

The Open event procedure for each report goes a follows:

Private Sub Report_Open(Cancel As Integer)

Const FORMNOTOPEN = 2450
Dim frm As Form

On Error Resume Next
Set frm = Forms!frmnamedlg
If Err = FORMNOTOPEN Then
DoCmd.OpenForm "frmNameDlg", OpenArgs:=Me.Name
Cancel = True
Else
If Err <> 0 Then
' unknown error
MsgBox Err.Description, vbExclamation, "Error"
Else
If Not IsNull(frm.txtLastName) Then
Me.Filter = "LastName= """ & frm.txtLastName & """"
Me.FilterOn = True
Else
Me.FilterOn = False
End If
DoCmd.Close acForm, frm.Name
End If
End If

End Sub

The click event of a button on frmNameDlg to open the report goes like this:

Private Sub cmdOpenReport_Click()

Const REPORTCANCELLED = 2501

On Error Resume Next
DoCmd.OpenReport Me.OpenArgs, acViewPreview
Select Case Err.Number
Case 0
' no error so do nothing
Case REPORTCANCELLED
' anticipated error so do nothing
Case Else
'unknown error so inform user
MsgBox Err.Description
End Select

End Sub

To open the report in the application the OpenReport method is called from
somewhere, being sure to hande Err.Number 2501 as above. At this stage
frmNameDlg is not open. This raises an error in the report's Open event
procedure which causes the opening of the report to be cancelled and
frmNameDlg to be opened, with name of the report passed into its OpenArgs
property. When the button on the form is clicked the correct report is
opened by means of the form's OpenArgs property.

You could make the form a little more elaborate by hiding/showing controls
in it depending on the value of its OpenArgs property. That way you can have
different combinations of controls for different reports as appropriate.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top