"John Galt" <js**@yahoo.com> wrote in news:ePBTb.11242$Bv6.3291854
@news1.epix.net:
I need to save a report to an RTF and I am using OutputTo acReport:
DoCmd.OutputTo acReport, stDocName, acFormatRTF, TodaysDir & "-" &
"Name.rtf"
This command saves the report nicely, however I cannot filter the report
like I can on an OpenReport and providing a filter statement. Has anyone
found a good way to do this.
I do not want my user to open and preview the report. It must be done
programmatically.
I am using Access 2002.
Please advise.
Thanks in advance
One way is to set the RecordSource of your report to a saved query. Before
opening the report, modify the SQL of the query as in:
Const qryChargesName As String = "qryCharges"
Function fCreateAccountFile(strAccountNumber As String)
Dim qdf As QueryDef
Dim rcs As Recordset
Dim strFullPath As String
Set qdf = DBEngine(0)(0).QueryDefs(qryChargesName)
With qdf
.SQL = "SELECT * FROM tblCharges WHERE Sent = No And Account = " &
_
Chr(34) & strAccountNumber & Chr(34)
Set rcs = .OpenRecordset
With rcs
If .RecordCount <> 0 Then
strFullPath = Environ("temp") & _
"\" & "Chargeable Messages for " & strAccountNumber &
".rtf"
DoCmd.OutputTo _
acOutputReport, "rptCharges", acFormatRTF, strFullPath,
False
End If
End With
End With
Set rcs = Nothing
Set qdf = Nothing
End Function
Sub test()
fCreateAccountFile "905 690-2185"
End Sub
--
Lyle
(for e-mail refer to
http://ffdba.com/contacts.htm)