Hide Access Background and Show Reports

moishy

Registered User.
Local time
Today, 14:29
Joined
Dec 14, 2009
Messages
264
Hello all Experts,

I'm using the following function to hide the access background, the problem I'm experiencing is that although it works well with forms, reports open but are not displayed, in other words access freezes.

Here is the code:
Code:
Option Explicit

Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3

Private Declare Function apiShowWindow Lib "user32" _
                                       Alias "ShowWindow" (ByVal hwnd As Long, _
                                                           ByVal nCmdShow As Long) As Long

Function fSetAccessWindow(nCmdShow As Long)

    Dim loX As Long
    Dim loForm As Form
    Dim loReport As Report

    On Error Resume Next

    Set loForm = Screen.ActiveForm
    Set loReport = Screen.ActiveReport

    If Err <> 0 Then
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
    End If

    If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Or _
       nCmdShow = SW_SHOWMINIMIZED And loReport.Modal = True _
       Then
        MsgBox "Cannot minimize Access with " _
               & (loForm.Caption + " ") _
               & "form on screen"
    ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Or _
           nCmdShow = SW_HIDE And loReport.PopUp <> True _
           Then
        MsgBox "Cannot hide Access with " _
               & (loForm.Caption + " ") _
               & "form on screen"
    Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
    End If
    fSetAccessWindow = (loX <> 0)
End Function
I call the function in the On Open event of the startup form like this: Call fSetAccessWindow(0)

Attached is a sample file that illustrates the issue, just open any report.
 

Attachments

Hello all Experts,

I'm using the following function to hide the access background, the problem I'm experiencing is that although it works well with forms, reports open but are not displayed, in other words access freezes.

Here is the code:
Code:
Option Explicit
 
Global Const SW_HIDE = 0
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWMAXIMIZED = 3
 
Private Declare Function apiShowWindow Lib "user32" _
                                       Alias "ShowWindow" (ByVal hwnd As Long, _
                                                           ByVal nCmdShow As Long) As Long
 
Function fSetAccessWindow(nCmdShow As Long)
 
    Dim loX As Long
    Dim loForm As Form
    Dim loReport As Report
 
    On Error Resume Next
 
    Set loForm = Screen.ActiveForm
    Set loReport = Screen.ActiveReport
 
    If Err <> 0 Then
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
        Err.Clear
    End If
 
    If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Or _
       nCmdShow = SW_SHOWMINIMIZED And loReport.Modal = True _
       Then
        MsgBox "Cannot minimize Access with " _
               & (loForm.Caption + " ") _
               & "form on screen"
    ElseIf nCmdShow = SW_HIDE And loForm.PopUp <> True Or _
           nCmdShow = SW_HIDE And loReport.PopUp <> True _
           Then
        MsgBox "Cannot hide Access with " _
               & (loForm.Caption + " ") _
               & "form on screen"
    Else
        loX = apiShowWindow(hWndAccessApp, nCmdShow)
    End If
    fSetAccessWindow = (loX <> 0)
End Function
I call the function in the On Open event of the startup form like this: Call fSetAccessWindow(0)

Attached is a sample file that illustrates the issue, just open any report.

I know this is a little old, but I figured I would put this code up for anyone else having this problem.

Code:
Private Sub CommandButton_Click()
fSetAccessWindow (SW_SHOWMAXIMIZED)
DoCmd.OpenReport ReportName, acViewReport, , , acDialog
Me.Visible = True
fSetAccessWindow (SW_HIDE)
End Sub

Basically you need to make the Access window visible before calling the report, then hide it again once the report is closed.
 

Users who are viewing this thread

Back
Top Bottom