Print/save current record into Snapshot Viewer

T

Tom

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
 
C

Crystal

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
 
T

Tom

Wow,

that a few more lines of code... 8)

I'll check it out and post my reply later.

Thanks already.

Tom


Crystal said:
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
 
T

Tom

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: (e-mail address removed)
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: (e-mail address removed)

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 said:
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
 
C

Crystal

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


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: (e-mail address removed)
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: (e-mail address removed)

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

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






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
 
C

Crystal

Hi Tom,

Oh, I see where you changed the code in SnapTheReport too --
this one was not as generic as it could be, I have changed
it for you and added a few comments

'--------------------------------

Sub SnapTheReport(pReportName As String, pFilter As String)

' written by Crystal
' Strive4peace2006 at yahoo.ca

'PARAMETERS
' pReportName = the name of your report
' pFilter = string to filter report or "" to get all

'USEAGE
'SnapTheReport "MyFriends","State='CO'"
'SnapTheReport "EmployeeInformation","EmpID=68"

Dim mFilename As String

'make a directory for snapshots if it does not already exist
On Error Resume Next
mFilename = CurrentProject.Path & "\Snapshots"
MkDir mFilename
On Error GoTo SnapTheReport_error

'create a filename to call the snapshot
' make it the report name and a date/time stamp

mFilename = CurrentProject.Path & "\Snapshots\" _
& Trim(pReportName & "_" & Format(Now(),
"yymmdd_h_nn")) & ".SNP"

'if a file with that name already exists, delete it
If Dir(mFilename) <> "" Then
Kill mFilename
DoEvents
End If

'save the filter before outputting the report
SetReportFilter pReportName, pFilter

'output the report to a snapshot file
DoCmd.OutputTo acOutputReport, pReportName, acFormatSNP,
mFilename

'clear the filter if you want to -- remove comment from
the next line
' SetReportFilter pReportName, ""

'if you do not want to open the SNAP file, comment out
the next line
Application.FollowHyperlink mFilename

SnapTheReport_exit:
Exit Sub

SnapTheReport_error:
Select Case Err.Number
Case 2501
Case Else
MsgBox Err.Description, , "ERROR " & Err.Number &
" SnapTheReport"
End Select
GoTo SnapTheReport_exit

End Sub

'--------------------------------

"how do I call the function from my command button?"

make an event procedure for your command button with the
following statement:

SnapTheReport"rptRRISSubmission", _
"[TrackingNumber] = " & nz(Me.TrackingNumber)

The snap procedure calls the procedure to set the filter --
both SnapTheReport and SetReportFilter can go into general
modules.

after you paste the code in, be sure to compile the database

---------- Compile ----------

Whenever you write or paste code, your should ALWAYS compile
it before you attempt to run it.

from the menu: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

-------------

a directory called Snapshots will be made below your
database directory (if it doesn't already exist) -- and that
is where the snapshot files will go


Have an awesome day

Warm Regards,
Crystal

MVP Microsoft Access
strive4peace2006 at yahoo.com


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: (e-mail address removed)
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: (e-mail address removed)

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

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






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
 

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