Link to home
Start Free TrialLog in
Avatar of sonmic
sonmic

asked on

Can't minimize my access application

Hi,

I want to minimize my access application when not needed. I have the code downloaded from the internet (see appendix). The SW_HIDE works fine but i cannot minimize. I get always an error because the active form is open.
How can i solve this.

tx
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 = Forms("frm_hoofdscherm").Form
    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 "Kan access niet minimaliseren met " _
                    & (loForm.Caption + " ") _
                    & "form op het scherm."
        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

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

how did you open the form "frm_hoofdscherm"?
can you upload a copy of the db..
Avatar of sonmic
sonmic

ASKER

Tx for your answer.

My DB is to large to sent.

In the OnOpen event i have the following code :
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Fout
    Dim strsql As String
    fSetAccessWindow (SW_HIDE)
    Dim i As Integer, CBtel As Integer
    For i = 1 To CommandBars.Count
        If CommandBars(i).Name <> " " Then
            If CommandBars(i).Visible = True Then
                If CommandBars(i).Name = "Menu Bar" Then
                    CommandBars("Menu Bar").Enabled = False
                    CBtel = CBtel + 1
                    arrCBs(CBtel) = CommandBars(i).Name
                Else
                    CommandBars(i).Visible = False
                    CBtel = CBtel + 1
                    arrCBs(CBtel) = CommandBars(i).Name
                End If
            End If
        End If
    Next i
    If CBtel = 0 Then
        arrCBs(1) = "Menu Bar"
        arrCBs(2) = "Database"
        arrCBs(2) = "Form design"
    End If
 
Exit_Fout: On Error Resume Next
    DoCmd.Hourglass False
    Exit Sub

Err_Fout:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Fout

End Sub
what are the setting of this form property  Popup, Modal?
When you use fSetAccessWindow, you must set your forms modal and popup properties to Yes.  But this doesn't minimize Access, it hides the Access window, leaving the forms standing on their own, without a background.

I've used this technique in the past, when clients demanded it, but if your application is very complicated, you will have to create all kinds of workarounds to deal with the popup and modal requirement.  And you will need to have really good error handling because errors will not popup in the vba window when Access is hidden.

Also, when you finally manage to hide the Access window, if you do minimize the active form, you will not see Access in the list of applications at the bottom of the page, instead, you will see it as a minimized form on your desktop.
HideAccess.mdb
Avatar of sonmic

ASKER

Both settings for modal and popup are Yes.
I only want a way, any way to minimize my application. Before i used the SW_HIDE, SW_NORMAL etc .... the minimize, maximize and Close buttons were not available.


this part of the code and the modal value is the one giving the error message
    If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then


how are you calling the codes to minimized the Access window?


this line
      If nCmdShow = SW_SHOWMINIMIZED And loForm.Modal = True Then

     means you can not minimize the Access window if the Active form Modal property is true

Avatar of sonmic

ASKER

Now i see it, but what can i do?
how are you calling the codes to minimized the Access window?
sonmic,

>>Before i used the SW_HIDE, SW_NORMAL etc .... the minimize, maximize and Close buttons were not available.

Do you mean the min, max, close buttons on the Access frame, or on your form?  To the best of my knowledge, you cannot affect the visibility of those on the Access frame (except by hiding the frame as you have done with fSetAccessWindow).  But now that you bring this up, why do you feel the need to hide the frame?  Is it because you don't want your users to be able to close the active form by clicking the Close button on the Access frame?  If so, there is a much better way to get around this.

In my example, if you check the forms ControlBox, and Min Max Buttons properties of the form, they are set to Yes and Both.  Is your form configured the same way.

You will notice that my code does not call the fSetAccessWindow until the Timer event fires (set at 1 second), which ensures that the form is loaded before the code runs.
ASKER CERTIFIED SOLUTION
Avatar of sonmic
sonmic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial