Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Location
    Orlando, FL, USA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Previewing Multiple Reports (Access 2002 SP-1)

    I have a form where I am using checkboxes to let users select which reports they want to print or preview. Allowing them to print multiple reports seems to be no problem, but if they elect to preview multiple reports all of them pop up at once. How can I get Access to wait until the user has finished previewing the first report before it displays the next selected report?

    Thanks!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Previewing Multiple Reports (Access 2002 SP-1)

    If you want your users to preview just one report at a time, why not use radio buttons instead of check boxes. Simpler for you and your users.

    If you want to keep the original design, you can use the following functon to check whether a specified report is open. It takes the name of the report as argument and returns True if the report is open, False otherwise.

    Function IsReportLoaded(ByVal strName As String) As Boolean
    Dim p As Integer
    If SysCmd(acSysCmdGetObjectState, acReport, strName) Then
    On Error Resume Next
    p = Reports(strName).Page
    IsReportLoaded = (Err = 0)
    End If
    End Function

    Repeat something like the following for each checkbox:

    If chkSomething.Value = True Then
    strReport = "rptSomething"
    DoCmd.OpenReport strReport, acViewPreview
    Do While IsReportLoaded(strReport)
    DoEvents
    Loop
    End If

  3. #3
    New Lounger
    Join Date
    Jan 2001
    Location
    Orlando, FL, USA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Previewing Multiple Reports (Access 2002 SP-1)

    Your suggestion worked, but I have read that using DoEvents in this manner will eat up CPU and sure enough as long as the report is being displayed Access dominates CPU big time.

    A colleague of mine suggested an alternate approach where you use a dynamic array to hold the names of the selected reports and then put some code in each report's close event to preview the next report in the array.

    In a module declare two global variables:
    Global StrReport() as string 'sets up a dynamic array
    Global lngI as Long 'counter

    Behind the Preview button on the form:
    ReDim strReport(0) 'Gets rid of any data currently in the strReport and sizes it as 0 (really holds 1 item)
    lngI = 0

    '--Quarterly Budget Report
    If Me.chkQBR.Value = True Then
    If Trim(strReport(UBound(strReport))) <> "" Then 'If the last array item is not empty add an element
    ReDim Preserve strReport(UBound(strReport) + 1) 'Add an element to the array
    End If
    strReport(UBound(strReport)) = "rptBudgetReport"
    End If

    '--Three Year History by Office Report
    If Me.chkFAO.Value = True Then
    If Trim(strReport(UBound(strReport))) <> "" Then 'If the last array item is not empty add an element
    ReDim Preserve strReport(UBound(strReport) + 1) 'Add an element to the array
    End If
    strReport(UBound(strReport)) = "rpt3YearFAOReport"
    End If
    '--repeat above as necessary

    '--preview first report in array
    DoCmd.OpenReport strReport(0), acPreview

    Behind the Close event in the reports:
    '--increment counter
    lngI = lngI + 1

    '--if the counter is less than or equal to the upper bound of the array _
    then preview next report in array
    If lngI <= UBound(strReport) Then
    DoCmd.OpenReport strReport(lngI), acPreview
    End If

    It works for me and the only CPU time that Access ties up is when the report is being created/formatted.

    Thanks,

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Previewing Multiple Reports (Access 2002 SP-1)

    Hi Tim,

    I'm glad you found a better solution. (Still another idea would have been to use the Timer event of the form, but there is no reason to try that now you've got it working.)

    Regards,
    Hans

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Previewing Multiple Reports (Access 2002 SP-1)

    Still another solution is demonstrated in one of the sample databases (probably Solutions) available either on the CD or by download. It uses automation and WithEvents to open instances of the same report based on different criteria. The last version I looked at used a public collection to store pointers to the individual report instances.
    Charlotte

Posting Permissions

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