Use One Query in Two Different Forms

keybs

Registered User.
Local time
Today, 23:14
Joined
Aug 16, 2001
Messages
12
I have 4 reports that use the same query. The query needs the JOBNUMBER as a parameter to search by and it gets it from a field in a form. If I want to run this same exact report/query from another form, am I going to have to copy the query and report or can I use both of the JOBNUMBER fields from the two different forms in the query's criteria?
 
Hi keybs

Why not do away with the criteria within the query and use a Link Criteria in the DoCmd OpenReport coding behind the button you click on your form.

------------------------------------------------------
Sub cmdJobReport_Click()
' Comments :
' Parameters : -
' Returns : -
' Created : 11/04/2000 Rich Gorvin
' Modified : 14/05/2001 Rich Gorvin
'
' --------------------------------------------------------
On Error GoTo Err_cmdJobReport_Click

Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "rptJobSummary"
strLinkCriteria = "[JobNumber] = Forms![frmSMyForm]![JobNumber]"
DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria

Exit_cmdJobReport_Click:
Exit Sub

Err_cmdJobReport_Click:
MsgBox Err.Description & _
" - (Error No:" & Err.Number & ")"
Resume Exit_cmdJobReport_Click

End Sub
----------------------------------------------------

You can then use this coding on each form to call up the report for the JobNumber of the current record each time - same query, same report, but can be used on numerous forms.

HTH

Rich Gorvin
 

Users who are viewing this thread

Back
Top Bottom