Specified criteria with OutoutTo

S

SF

Hi,

I have a button to export a report in snapshot view but I cann't specify
criteria for a specific report. Is there a way to provide criteria for
OutputTo ?


strPathandFileName = "r:\" & Me.listContractID & ".snp"
DoCmd.OutputTo acOutputReport, "rptGrandAgreement_e",
"SnapshotFormat(*.snp)", strPathandFileName

SF
 
A

Allen Browne

Correct: OutputTo lacks the WhereCondition that OpenReport has.

The workaround is to set up a filter string before you OutputTo, and use the
report's Open event to apply the filter.

1. In a standard module (created through the Modules tab of the Database
window), in the General Declarations section (top, just under the Option
statements), add this line:
Public gstrReportFilter As String.

2. In the Open event procedure of your form, read, apply, and clear the
string:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

3. Assign the filter to the string before OutputTo:
gstrReportFilter = "ClientID = 999:
DoCmd.OutputTo ...
 
S

SF

Great!.

Thank a lot

SF

Allen Browne said:
Correct: OutputTo lacks the WhereCondition that OpenReport has.

The workaround is to set up a filter string before you OutputTo, and use
the report's Open event to apply the filter.

1. In a standard module (created through the Modules tab of the Database
window), in the General Declarations section (top, just under the Option
statements), add this line:
Public gstrReportFilter As String.

2. In the Open event procedure of your form, read, apply, and clear the
string:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub

3. Assign the filter to the string before OutputTo:
gstrReportFilter = "ClientID = 999:
DoCmd.OutputTo ...
 

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