My table structures:
Master: (one record per group)
Group
Group Description
CostCtr: (multiple Cost Center per group
Group
Cost Center
Cost Center Description
Detail Transactions: (multiple Transactions per Cost Center)
Cost Center
Account Number
Voucher
Amount
Date
I have a query that links these three files and receives selection criteria from a Form:
Date From
Date To
Group to Report
The Form also has input fields for the folder names of the Fiscal Year and Fiscal Month that are used to complete the location to store the resulting .pdf report. Also on the Form is a list box created from the Master file to aid in selecting the group to report. All has worked well up to now. What has happened is that the number of groups has grown to make single selection of each group too tedious. I have been trying to alter the code to loop through Master table and run the same report for each record but I'm at a loss to figure it out. I will post my current code (no snickering) that is a mix of bits and pieces from here and there.
Let me know if you need more information....
Private Sub Command3_Click()
Dim dbsCopy As DAO.Database
Dim rstGroups As DAO.Recordset
Dim intI As Integer
Dim strFY As String
Dim strFM As String
Dim strSelect As String
Dim strLocation As String
Dim strPath As String
Dim strReport As String
Dim strExt As String
Let strFY = [Forms]![Main]![txtFY] & "\"
Let strFM = [Forms]![Main]![txtFM] & "\"
Let strPath = "G:\Group\SMCACCT\PEGGY\SHELTER\EARN ANAL\"
Set dbsCopy = CurrentDb
Set rstGroups = dbsCopy.OpenRecordset("Master")
'If the recordset is empty, exit.
If rstGroups.EOF Then Exit Sub
intI = 1
With rstGroups
Do Until .EOF
Let strSelect = ![Group] & "\"
Let strPath = "G:\Group\SMCACCT\PEGGY\SHELTER\EARN ANAL\"
Let strReport = "CummTransHistory - " & ![Group]
Let strExt = ".pdf"
Let strLocation = strPath & strFY & strFM & strSelect & strReport & strExt
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("Cumm Trans History Query")
qdf.SQL = Replace(Replace(qdf.SQL, "Group", ![Group]))
DoCmd.OutputTo acOutputReport, "Cumm Trans History Report - Select a Group", "PDFFormat(*.pdf)", strLocation, False, "", 0, acExportQualityPrint
.MoveNext
intI = intI + 1
Loop
End With
rstGroups.Close
dbsCopy.Close
Set rstGroups = Nothing
Set dbsCopy = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub
Master: (one record per group)
Group
Group Description
CostCtr: (multiple Cost Center per group
Group
Cost Center
Cost Center Description
Detail Transactions: (multiple Transactions per Cost Center)
Cost Center
Account Number
Voucher
Amount
Date
I have a query that links these three files and receives selection criteria from a Form:
Date From
Date To
Group to Report
The Form also has input fields for the folder names of the Fiscal Year and Fiscal Month that are used to complete the location to store the resulting .pdf report. Also on the Form is a list box created from the Master file to aid in selecting the group to report. All has worked well up to now. What has happened is that the number of groups has grown to make single selection of each group too tedious. I have been trying to alter the code to loop through Master table and run the same report for each record but I'm at a loss to figure it out. I will post my current code (no snickering) that is a mix of bits and pieces from here and there.
Let me know if you need more information....
Private Sub Command3_Click()
Dim dbsCopy As DAO.Database
Dim rstGroups As DAO.Recordset
Dim intI As Integer
Dim strFY As String
Dim strFM As String
Dim strSelect As String
Dim strLocation As String
Dim strPath As String
Dim strReport As String
Dim strExt As String
Let strFY = [Forms]![Main]![txtFY] & "\"
Let strFM = [Forms]![Main]![txtFM] & "\"
Let strPath = "G:\Group\SMCACCT\PEGGY\SHELTER\EARN ANAL\"
Set dbsCopy = CurrentDb
Set rstGroups = dbsCopy.OpenRecordset("Master")
'If the recordset is empty, exit.
If rstGroups.EOF Then Exit Sub
intI = 1
With rstGroups
Do Until .EOF
Let strSelect = ![Group] & "\"
Let strPath = "G:\Group\SMCACCT\PEGGY\SHELTER\EARN ANAL\"
Let strReport = "CummTransHistory - " & ![Group]
Let strExt = ".pdf"
Let strLocation = strPath & strFY & strFM & strSelect & strReport & strExt
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("Cumm Trans History Query")
qdf.SQL = Replace(Replace(qdf.SQL, "Group", ![Group]))
DoCmd.OutputTo acOutputReport, "Cumm Trans History Report - Select a Group", "PDFFormat(*.pdf)", strLocation, False, "", 0, acExportQualityPrint
.MoveNext
intI = intI + 1
Loop
End With
rstGroups.Close
dbsCopy.Close
Set rstGroups = Nothing
Set dbsCopy = Nothing
Exit Sub
ErrorHandler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Sub