none
how to work with two dialog foms side by side RRS feed

  • Question

  • I'm trying to have my Access application window hidden and two forms on the screen, side by side, with me free to move from one form to the other as i want.

    I'm using ShowWindow(Application.hWndAccessApp, SW_HIDE) to hide the Access window and setting the forms as dialog (not just pop-up) in order to keep them on the screen.

    After the login, I open both the dialog forms and on the open event of the first form I hide the Access window

    At that point  everything is fine and I can use both the forms side by side, even if they are set as dialog.

    The problem arise when I close one of them, because, when I reopen it, it keeps the focus and it is impossible to move to the other form, unless to close it.

    Does anyone knows how to fix it? Please help me out! Thank you all very much!!!

    Thursday, October 8, 2015 10:54 AM

Answers

  • ...however, may be I'm making things more complicated than I need and resize the Access Window (insted to hide it) could be a good solution too.

    Is there a command to do that? I can't find how to work on it.

    You could minimize the Access application window, while keeping the forms on the screen.  The forms would have to be set as PopUp but not Modal, and you'd need to have a function like this by Dev Ashish (from The Access Web) in 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 Function apiShowWindow Lib "user32" _
        Alias "ShowWindow" (ByVal hWnd As Long, _
              ByVal nCmdShow As Long) As Long
    
    Function fSetAccessWindow(nCmdShow As Long)
    'Usage Examples
    'Maximize window:
    '       ?fSetAccessWindow(SW_SHOWMAXIMIZED)
    'Minimize window:
    '       ?fSetAccessWindow(SW_SHOWMINIMIZED)
    'Hide window:
    '       ?fSetAccessWindow(SW_HIDE)
    'Normal window:
    '       ?fSetAccessWindow(SW_SHOWNORMAL)
    '
    Dim loX  As Long
    Dim loForm As Form
        On Error Resume Next
        Set loForm = Screen.ActiveForm
        If Err <> 0 Then 'no Activeform
          If nCmdShow = SW_HIDE Then
            MsgBox "Cannot hide Access unless " _
                        & "a form is on screen"
          Else
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
            Err.Clear
          End If
        Else
            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
        End If
        fSetAccessWindow = (loX <> 0)
    End Function
    

    Then in your form's Open event you could have the following code:

    Private Sub Form_Open(Cancel As Integer)
    
        Me.Visible = True
        DoEvents
        fSetAccessWindow SW_SHOWMINIMIZED
    
    End Sub
    

    There is a RunCommand instruction to minimize the Access window, RunCommand acCmdAppMinimize, but I find that it also minimizes the open forms, even if they are in PopUp mode.  So I tested this version, using the ShowWindow api, and it worked.  Note: I didn't test it under 64-bit Windows, so it's possible that the code will need tinkering with; however, it ought to work in principle.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, October 8, 2015 4:14 PM

All replies

  • It is not clear as to what is the benefit/intent of your approach rather than more simply using standard forms, and manipulating their visibility (or simply opening/closing them).
    Thursday, October 8, 2015 1:32 PM
  • The intent is to work with more that one form while Access window is hidden.

    However, after I hide It, I can keep the forms on the screen only if they are set as dialog.

    am I using a wrong approach?
    Thursday, October 8, 2015 1:43 PM
  • I guess since we are Access developers - thus making applications whereby users use Access - so that the idea of hiding the Access window is a bit different.  One can easily hide the ribbon & navigation pane in order to totally control the user experience - and the user surely knows he is using an application (not necessarily that it is Access) and so there does not seem to be a compelling reason to actually close the Access window itself - unless I misunderstand the terminology that is being used.
    Thursday, October 8, 2015 1:56 PM
  • The point is not to hide Access to the user; but, since I don't need any ribbon, nor navigation panel,  I would find a way to manage the background window while the user is working, just to avoid another window on the screen that is useless to the user.

    Do you think it makes any sense?

    Thursday, October 8, 2015 2:18 PM
  • It does make sense to only present to the user only what they need to see - without other distractions.

    I would option the navigation pane to be not visible.  Make the ribbon not visible.  And then present normal forms as appropriate. 

    Thursday, October 8, 2015 2:28 PM
  • ...however, may be I'm making things more complicated than I need and resize the Access Window (insted to hide it) could be a good solution too.

    Is there a command to do that? I can't find how to work on it.

    Thursday, October 8, 2015 2:40 PM
  • ...however, may be I'm making things more complicated than I need and resize the Access Window (insted to hide it) could be a good solution too.

    Is there a command to do that? I can't find how to work on it.

    You could minimize the Access application window, while keeping the forms on the screen.  The forms would have to be set as PopUp but not Modal, and you'd need to have a function like this by Dev Ashish (from The Access Web) in 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 Function apiShowWindow Lib "user32" _
        Alias "ShowWindow" (ByVal hWnd As Long, _
              ByVal nCmdShow As Long) As Long
    
    Function fSetAccessWindow(nCmdShow As Long)
    'Usage Examples
    'Maximize window:
    '       ?fSetAccessWindow(SW_SHOWMAXIMIZED)
    'Minimize window:
    '       ?fSetAccessWindow(SW_SHOWMINIMIZED)
    'Hide window:
    '       ?fSetAccessWindow(SW_HIDE)
    'Normal window:
    '       ?fSetAccessWindow(SW_SHOWNORMAL)
    '
    Dim loX  As Long
    Dim loForm As Form
        On Error Resume Next
        Set loForm = Screen.ActiveForm
        If Err <> 0 Then 'no Activeform
          If nCmdShow = SW_HIDE Then
            MsgBox "Cannot hide Access unless " _
                        & "a form is on screen"
          Else
            loX = apiShowWindow(hWndAccessApp, nCmdShow)
            Err.Clear
          End If
        Else
            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
        End If
        fSetAccessWindow = (loX <> 0)
    End Function
    

    Then in your form's Open event you could have the following code:

    Private Sub Form_Open(Cancel As Integer)
    
        Me.Visible = True
        DoEvents
        fSetAccessWindow SW_SHOWMINIMIZED
    
    End Sub
    

    There is a RunCommand instruction to minimize the Access window, RunCommand acCmdAppMinimize, but I find that it also minimizes the open forms, even if they are in PopUp mode.  So I tested this version, using the ShowWindow api, and it worked.  Note: I didn't test it under 64-bit Windows, so it's possible that the code will need tinkering with; however, it ought to work in principle.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Thursday, October 8, 2015 4:14 PM