(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.
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
|