Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Reports: Handle reports from a modal form

Author(s)
Dev Ashish

(Q) I have a form from which I call various reports using the method
        docmd.OpenReport strReportName, acPreview
   
    However, the form which allows the users to select a report is opened in modal view, by
    docmd.OpenForm strFormname, , , , , acDialog

The problem is I can't select any Report Preview menu options or the Report itself as it's opened behind this modal form. How can I have the report to come up in front of the form so that it has the focus.

(A) Use the OpenReport sub in the code below by Terry Kreft in the same manner as you use the OpenReport method.

'************ Code Start **********
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Terry Kreft
'
Sub OpenReport(ReportName As String, Optional View As Integer, Optional _
    FilterName As String, Optional WhereCondition As String)
Dim loFormArray() As String
Dim loform As Form
Dim intCount As Integer
Dim intX As Integer
    For Each loform In Forms
        If loform.Visible Then
            ReDim Preserve loFormArray(intCount)
            loFormArray(intCount) = loform.Name
            loform.Visible = False
            intCount = intCount + 1
        End If
    Next
    DoCmd.OpenReport ReportName, View, FilterName, WhereCondition
    Do While IsVisible(acReport, ReportName): DoEvents: Loop
    For intX = intCount - 1 To 0 Step -1
        Forms(loFormArray(intX)).Visible = True
    Next
End Sub
Function IsVisible(intObjType As Integer, strObjName As String) As Boolean
Dim intObjState As Integer
    intObjState = SysCmd(acSysCmdGetObjectState, intObjType, strObjName)
    IsVisible = intObjState And acObjStateOpen
End Function
'*********** Code End **************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer