Solved

Using VBA export reports to rtf files with criteria

Posted on 2008-10-02
2
1,555 Views
Last Modified: 2013-11-27
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.
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

Open in new window

0
Comment
Question by:eshurak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 22626870
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 ......
0
 
LVL 3

Author Comment

by:eshurak
ID: 22627034
Yeah, I just wrote the code below using a similer concept.  It works, but it's ugly.
Dim sql As String
Dim qd As QueryDef
 
Set qd = CurrentDb.QueryDefs("ReportData")
 
With CurrentDb.OpenRecordset("Select Distinct Department from new;", dbOpenForwardOnly)
    While Not .EOF
    
    sql = "SELECT * FROM new WHERE (((new.Department)='" & !Department & "'));"
    qd.sql = sql
    
    
    DoCmd.OutputTo acOutputReport, "testreport", acFormatRTF, "C:\rtf\" & !Department & ".rtf"
    
        .MoveNext
    Wend
.Close
End With

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question