Hi Tom,
You need to set the report filter and save it.
Private Sub SnapTheReport(pReportName As String, pFilename
As String)
Dim mFilename As String
'make directory for SNAP reports
'if it is already there, skip error message
On Error Resume Next
mFilename = CurrentProject.Path & "\Snapshots"
MkDir mFilename
On Error GoTo SnapTheReport_error
mFilename = CurrentProject.Path & "\Snapshots\" _
& Trim(pReportName & "_" & Format(Now(),
"yymmdd_h_nn")) & ".SNP"
If Dir(mFilename) <> "" Then
Kill mFilename
DoEvents
End If
'gCrit is a global variable with the report filter
information
'in your case, you would use
'"[TrackingNumber] = " & nz(Me.TrackingNumber)
SetReportFilter pReportName, gCrit
DoCmd.OutputTo acOutputReport, pReportName, acFormatSNP,
mFilename
Application.FollowHyperlink mFilename
SnapTheReport_exit:
Exit Sub
SnapTheReport_error:
Select Case Err.Number
Case 2501: GoTo SnapTheReport_exit
Case Else
MsgBox Err.Description, , "ERROR " & Err.Number &
" SnapTheReport"
'IsAdmin is a function that I set to
'TRUE when developing
'FALSE when I give it to the user
If IsAdmin() Then
Stop
Resume
End If
goto SnapTheReport_exit
End Select
End Sub
'------------------------------------ SetReportFilter
Sub SetReportFilter(pReportName As String, pFilter As String)
'Save a filter to the specified report
'You can do this before you send a report in an email
message
'You can use this to filter subreports instead of
putting criteria in the recordset
' USEAGE:
' example: in code that processes reports for viewing,
printing, or email
' SetReportFilter "MyReportname","someID=1000"
' SetReportFilter "MyAppointments","City='Denver' AND
dt_appt=#9/18/05#"
' written by Crystal
' (e-mail address removed)
' PARAMETERS:
' pReportName is the name of your report
' pFilter is a valid filter string
On Error GoTo SetReportFilter_error
'---------- declare variables
Dim rpt As Report
'---------- open design view of report and set the
report object variable
DoCmd.OpenReport pReportName, acViewDesign
Set rpt = Reports(pReportName)
'---------- set report filter and turn it on
rpt.Filter = pFilter
rpt.FilterOn = IIf(Len(pFilter) > 0, True, False)
'---------- save and close the changed report
' DoCmd.Save acReport, pReportName
DoCmd.Close acReport, pReportName, acSaveYes
'---------- Release object variable
Set rpt = Nothing
Exit Sub
SetReportFilter_error:
Resume Next
MsgBox Err.Description, , "ERROR " & Err.Number & "
SetReportFilter"
'press F8 to step thru code and fix problem
Stop
Resume
'next line will be the one with the error
End Sub
Have an awesome day
Warm Regards,
Crystal
MVP Microsoft Access
(e-mail address removed)
I normally use the following line to print my current record (OnClick event)
into an Access report. It works great.
DoCmd.OpenReport "ReportName", acViewPreview, , "[TrackingNumber] = " &
Me.TrackingNumber
Now, in another application, I use Snapshot Viewer (to maintain formatting
of report). I thought I applied the same principle of the DoCmd line...
obviously I don't as all records are saved into the Snapshot Viewer file
when clicking on the command button.
DoCmd.OutputTo acOutputReport, "rptRRISSubmission", acFormatSNP, , ,
"[TrackingNumber] = " & Me.TrackingNumber
How do I modify the line above so that I only output the current record into
Snapshot Viewer?
Tom