我有一个带有列表框和日期选择器的表单。当我输入日期并从列表框中选择40个项目中的一个并单击我的按钮时,我能够生成一个报告。我的问题是,如何循环遍历所有40个项目并将每个报告导出为pdf?任何帮助将不胜感激。此外,我希望每个报告使用与列表框中相同的名称进行保存。防爆。第一份报告名为RHM1,依此类推。
Private Sub Command3_Click()
MyFilter = "rptIncidentsByOrg"
MyPath = "C:\ComplyTrack\"
MyFilename = "Test.pdf"
For Each varItem In Me.lstActivityOrgs.ItemsSelected
Debug.Print Me.lstActivityOrgs.Column(0, varItem)
DoCmd.OpenReport "rptIncidentsByOrg", acViewPreview, , "([Activity Org] = " & Chr(34) & Me.lstActivityOrgs.Column(0, i) & Chr(34) & ")"
DoCmd.OutputTo acOutputReport, "rptIncidentsByOrg", acFormatPDF, MyPath & MyFilename, True
DoCmd.Close acReport, "Test"
Next varItem
End Sub
答案 0 :(得分:0)
更新选项' B'对于文件名......
尝试类似:(根据需要更改COLUMN)
A. To list only items selected:
Private Sub Command3_Click()
For Each varItem In Me.lstActivityOrgs.ItemsSelected
Debug.Print Me.lstActivityOrgs.Column(0, varItem)
DoCmd.OpenReport "rptIncidentsByOrg", acViewPreview, , "([Activity Org] = " & Chr(34) & Me.lstActivityOrgs.Column(XXX,varItem) & Chr(34) & ")"
Next varItem
End Sub
Or B. List All Items:
Private Sub Command3_Click()
MyFilter = "rptIncidentsByOrg"
MyPath = "C:\ComplyTrack\"
MyFilename = "<fromListBox>.pdf"
For i = 0 To Me.lstActivityOrgs.ListCount
MyFileName = Me.lstActivityOrgs.Column(0, i) & ".pdf"
Debug.Print Me.lstActivityOrgs.Column(0, i)
DoCmd.OpenReport "rptIncidentsByOrg", acViewPreview, , "([Activity Org] = " & Chr(34) & Me.lstActivityOrgs.Column(XXX,i) & Chr(34) & ")"
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, MyPath & MyFileName
DoCmd.Close acReport, "rptIncidentsByOrg"
Next i
End Sub