Question : Using VBA export reports to rtf files with criteria

Hello,

I'm trying to export a report to an various rtf files depending on criteria.  The code currently loops through a record set and will export the file but how do I pass it crieria to limit the record set.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
With CurrentDb.OpenRecordset("Select Distinct Department from new;", dbOpenForwardOnly)
    While Not .EOF      
        DoCmd.OutputTo acOutputReport, "testreport", acFormatRTF, "C:\exports\" & !Department
   
        .MoveNext
    Wend
.Close
End With

Answer : Using VBA export reports to rtf files with criteria

You can't easily.
OutputTo doesn't use filters or Where clauses.

You willhave to find some way of setting the report's recordsource based on the department.
Maybe setting the report's query sql to a value that includes the dapartment criteria.


strsql = " Select * from table where dpartment = '" &  rs!department & "'"
currentdb.querydefs("reportqueryname").sql = strsql
docmd.outputto ......
Random Solutions  
 
programming4us programming4us