Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2011
    Posts
    56

    Unanswered: Batch Output Report

    Access 2007

    I am working on vba code that will allow me to "batch" output pdf reports. In order to open and output a single report, I use DoCmd.OpenReport, DoCmd.OutputTo and DoCmd.Close. Is there a way to repeat this process over and over again for values selected in a multiselect list?

  2. #2
    Join Date
    Jul 2012
    Posts
    7
    Not sure if this is what you are looking for. This will run each output separately, not as one batch report file.

    Assuming that the Report name is the First Column of the listbox

    Code:
    Dim strReportName as String
    Dim varItem as Variant
    With Me.lstName 'your list name
    For Each varItem in .ItemsSelected
    strReportName = .ItemData(varItem)
    'run your output code here using strReportName as the Report name
    Next
    End With

  3. #3
    Join Date
    Aug 2011
    Posts
    56
    Code:
    Dim rptWhere As String
    Dim rptEquipID As String
    Dim rptName As String
    Dim fileName As String
    Dim filePath As String
    Dim rptCurrent As Report
    Dim varItem as Variant
    
    rptName = "rptServiceChecklist"
    
    With Me.lstEquipID 'list with Equipment IDs
    
    For Each varItem in .ItemsSelected
    rptEquipID = .ItemData(varItem)
    rptWhere = "[tblEquipment].[ID]= rptEquipID"
    DoCmd.OpenReport rptName, acViewPreview, , rptWhere
    Set rptCurrent = Screen.ActiveReport
    fileName = rptCurrent.Caption
    filePath = (Folder Name) & "\" & fileName & ".pdf"
    DoCmd.OutputTo acOutputReport, rptCurrent.Name, acFormatPDF, filePath, False
    
    Next
    End With
    Using the code you posted, I have added what I already started to accomplish what I want....I think. The idea is to print a checklist for each selected Equipment ID to individual files in a folder. Is that correct?

  4. #4
    Join Date
    Jul 2012
    Posts
    7
    Two Things:
    1, Im assuming rptEquipID is a number (it should be if it is an id in a table), if so, you need to declare it as long,
    Code:
    Dim rptEquipID as Long
    2, you need to change your where condition to
    Code:
    rptWhere = "[tblEquipment].[ID]= " & rptEquipID

  5. #5
    Join Date
    Aug 2011
    Posts
    56
    Yes it is a number. Thank you for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •