'Minimize Access, but keep popup form on the screen

I want to separate the popup form that I created from Access.

So far:

  1. I changed the "Pop up" setting of the form to "Yes".
  2. I selected the form as the "Display Form" in the "Current Database" options.
  3. I found a function that would minimize Access.
Option Compare Database
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
On Error Resume Next
Set loForm = Screen.ActiveForm

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

If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
    MsgBox "Cannot minimize Access with " _
      & (loForm.Caption + " ") _
      & "form on screen"
ElseIf nCmdShow = SW_HIDE And loForm.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
  1. I call that function on Form_Load to open only the form and minimize the Access window.

I noticed that if I open the Access window and then press the "minimize" button it will also minimize the form.

I was wondering if I will be able to separate the two so when I minimize the Access window the form would still remain on the screen?



Solution 1:[1]

We can hide access instance by keeping form visible. So, write below codes to a standard module.

Option Compare Database   
Option Explicit

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

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

Function fSetAccessWindow(nCmdShow As Long)
' call fSetAccessWindow(0) for hiding access window
' call fSetAccessWindow(1) for showing access window
' call fSetAccessWindow(2) for minimizing access window
' call fSetAccessWindow(3) for maximizing access window

    Dim loX As Long
    Dim loForm As Form
    On Error Resume Next
    Set loForm = Screen.ActiveForm

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

    If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then
        MsgBox "Cannot minimize Access with " _
        & (loForm.Caption + " ") _
        & "form on screen"
    ElseIf nCmdShow = SW_HIDE And loForm.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

Then call function with proper argument to hide access window. Like-

Private Sub CmdHideAccess_Click()
    Call fSetAccessWindow(0)
End Sub

Read function comments carefully for more argument if you need.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harun24hr