Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to loop through query and output multiple reports (Access)?

Status
Not open for further replies.

TomYC

Technical User
Dec 11, 2008
191
US
I need help with this step!
I can generate reports from a form on which I choose a date range, and select one or more fields in drop downs (eg. "Unit"); I can do one at a time, but I'd like to generate all reports that have data, i.e., where the report query in the date range does not return NULL.

Here is my code for a single report, output as .snp:

Private Sub UnitReport_Click()
On Error GoTo Err_UnitReport_Click

Dim stDocName As String
Dim stPrintFileName As String
Dim stDate As String
Dim stUnit As String
stDocName = "detail_unit"
stUnit = Forms![f_rpt]![cbUnit]
stDate = Format(Forms![f_rpt]![cbFromDate], "mmddyy")

stPrintFileName = stUnit & "_" & stDate

DoCmd.OutputTo acReport, stDocName, "Snapshot Format", "S:\Walkround\Report\" & stPrintFileName & ".snp", False

Exit_UnitReport_Click:
Exit Sub

Err_UnitReport_Click:
MsgBox Err.Description
Resume Exit_UnitReport_Click

End Sub

What I'd like to do is code such that I don't use the combobox cbUnit field but rather find that field ("Unit") from either a query ("q_UnitHasData") that returns a list of Units with data within the date range, or work with all possible field values for "Unit" and use something like Report.HasData.

This must be easy, right? Is this enough information to go on?
Thanks,
Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top