Re: set filter on report and output as SNAPshot



Hi Tom,

I see I left my IsAdmin test in there...

make a function in your general module

Function IsAdmin() as boolean
IsAdmin = true
End Function

I do this so I can easily switch beteen breaking the code while I am developing and stopping it when I give it to a user -- then you would set IsAdmin = false

This in ONE thing that will keep the code from compiling...

now, the purpose of SetReportFilter is for you to give it the name of a report and a filter string to use...

ie:
SetReportFilter "rptRRISSubmission", "SubmitID=8"

Do not change the code in the generic function! It is written so that it can be used by any report anytime...

What does your filter string look like? I just made one up to demonstrate, "SubmitID=8"

After you write or paste code, you need to compile it

from the menu in a module window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com



Tom wrote:
Crystal,

again, thanks for the code. I doubt that I have made proper updates.
Also, how do I call the function from my command button?

Below is the code (I temporarily removed the comments for reposting it).
What am I missing or did wrong?

===============================================

Private Sub SnapTheReport(pReportName As String, pFilename As String)

'written by Crystal: Strive4peace2004@xxxxxxxx
Dim mFilename As String

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

SetReportFilter pReportName, [TrackingNumber] = " &
nz(Me.TrackingNumber)"

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"
If IsAdmin() Then
Stop
Resume
End If
GoTo SnapTheReport_exit
End Select
End Sub

===============================================

Sub SetReportFilter(pReportName As String, pFilter As String)

'written by Crystal: Strive4peace2004@xxxxxxxx

On Error GoTo SetReportFilter_error
Dim rpt As Report

DoCmd.OpenReport rptRRISSubmission, acViewDesign
Set rpt = Reports(rptRRISSubmission)

rpt.Filter = pFilter
rpt.FilterOn = IIf(Len(pFilter) > 0, True, False)

DoCmd.Close acReport, rptRRISSubmission, acSaveYes

Set rpt = Nothing

Exit Sub

SetReportFilter_error:
Resume Next

MsgBox Err.Description, , "ERROR " & Err.Number & " "
SetReportFilter ""
Stop
Resume
End Sub

===============================================






"Crystal" <strive4peace2006@xxxxxxxxx> wrote in message
news:e#2kdE4MGHA.1832@xxxxxxxxxxxxxxxxxxxxxxx

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
' Strive4peace2004@xxxxxxxx

' 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
strive4peace2006@xxxxxxxxx


Tom wrote:

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





.