hide Access Window (1 Viewer)

bhelmy

Registered User.
Local time
Today, 10:03
Joined
Dec 6, 2015
Messages
62
need to hide access window when open form


WIn64
 

Attachments

  • New Microsoft Access Database.accdb
    588 KB · Views: 242
Last edited:

leanpilar

Registered User.
Local time
Today, 09:03
Joined
Aug 13, 2015
Messages
94
Try this...
I add a new module with one function and event on load on your form to hide and 3 btn for other options
 

Attachments

  • New Microsoft Access Database.accdb
    608 KB · Views: 321

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:03
Joined
May 7, 2009
Messages
19,233
i tested it, it only minimized, when tried hiding the main app, it hides together with the form.
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 03:03
Joined
Oct 17, 2012
Messages
3,276
Here's a slightly longer version of the same code that I use.

To use it, call the function fAccessWindow, using 'hide' to hide the Access window, and 'show' to show it again. Also, please note that the ONLY forms that will show up are those marked as pop-ups; the rest are hidden with the background.

Code:
Option Compare Database
Option Explicit
Option Base 0

'==============================
'  CONSTANTS FOR DBASE WINDOW
'==============================
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
 
'==========================
'  DBASE WINDOW FUNCTIONS
'==========================
Public Declare PtrSafe Function IsWindowVisible Lib "user32" _
        (ByVal hWnd As Long) _
    As Long
Public Declare PtrSafe Function ShowWindow Lib "user32" _
        (ByVal hWnd As Long, _
        ByVal nCmdShow As Long) _
    As Long
 
'============================
' FORM MANAGEMENT FUNCTIONS
'============================
 
Public Function fAccessWindow(Optional Procedure As String, _
    Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
'****************************************************************************************
'* Purpose:  Controls the behavior and appearance of the Daatabase window               *
'*           residing on the form, and hence, we reduce the overall size of the FE DB.  *
'* Accepts:  Procedure -    describes the behavior requested                            *
'*           SwitchStatus - (optional) instructs the procedure to switch the current    *
'*                          status of the DB Window                                     *
'*           StatusCheck -  (optional) allows the procedure to check the current status *
'*                          of the DB window to determine whether or not to initiate a  *
'*                          change                                                      *
'****************************************************************************************
On Error GoTo EH
    Dim dwReturn As Long
    If Procedure = "Hide" Then
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
    End If
    If Procedure = "Minimize" Then
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMINIMIZED)
    End If
    If Procedure = "Normal" Then
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWNORMAL)
    End If
    If Procedure = "Show" Then
        dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
    End If
    If SwitchStatus = True Then
        If IsWindowVisible(hWndAccessApp) = 1 Then
            dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
        Else
            dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
        End If
    End If
    If StatusCheck = True Then
        If IsWindowVisible(hWndAccessApp) = 0 Then
            fAccessWindow = False
        End If
        If IsWindowVisible(hWndAccessApp) = 1 Then
            fAccessWindow = True
        End If
    End If
    Exit Function
EH:
    MsgBox "There was an error resetting the Database Window!  " & _
        "Please contact your Database Administrator.", vbCritical, "Error!"
    Exit Function
End Function
 
Public Function RestoreForm(FormName As String)
'**********************************************************************************
'* Purpose:  Manages the database window, keep the current form on top of others. *
'* Accepts:  FormName is the name of the Form which you want to restore           *
'* Returns:  N/A                                                                  *
'*   Usage:  Add "RestoreForm Me.Form.Name" to the OnOpen event of a form         *
'**********************************************************************************
On Error GoTo EH
    fAccessWindow "Minimize", False, False
    DoCmd.SelectObject acForm, FormName
    DoCmd.Restore
    Exit Function
EH:
    MsgBox "There was an error restoring the Form.  " & _
        "Please contact your Database Administrator.", vbOKOnly, "Error!"
    Exit Function
End Function
 

Nightowl4933

Tryin' to do it right...
Local time
Today, 08:03
Joined
Apr 27, 2016
Messages
151
Hi Frothingslosh,

Thanks for making the code available.

I have tried to use your code, but before I even got to try it, the Code window shows some of the text in red, as per the attached image. I copied the text directly from your post in the forum.

Does this need to be in it's own Module, or can it be in any one? The text is red in either case.

Thank you,

Pete
 

Attachments

  • Screen Shot 2016-05-29 at 14.49.18.png
    Screen Shot 2016-05-29 at 14.49.18.png
    43.4 KB · Views: 272

sneuberg

AWF VIP
Local time
Today, 00:03
Joined
Oct 17, 2014
Messages
3,506
Probably easier for you just to put it in it own module.
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:03
Joined
Sep 21, 2011
Messages
14,267

Nightowl4933

Tryin' to do it right...
Local time
Today, 08:03
Joined
Apr 27, 2016
Messages
151
OK, thanks.

Could I get around this by changing references to 'user32' to 'LoadCursorA', or am I being a dolt?

Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:03
Joined
Sep 21, 2011
Messages
14,267
OK, thanks.

Could I get around this by changing references to 'user32' to 'LoadCursorA', or am I being a dolt?

Thanks

No, that is just an example using another function in user32.dll
I only have a 32bit system, so might be on the wrong path?

Just surround your code with the #VBA7 test?
Try it, what do you have to lose?

I am on Access 2007 and my VBA is 6.5

HTH
Code:
#IF VBA7
Public Declare PtrSafe Function IsWindowVisible Lib "user32" _
        (ByVal hWnd As Long) _
    As Long
Public Declare PtrSafe Function ShowWindow Lib "user32" _
        (ByVal hWnd As Long, _
        ByVal nCmdShow As Long) _
    As Long
#ELSE
Public Declare Function IsWindowVisible Lib "user32" _
        (ByVal hWnd As Long) _
    As Long
Public Declare Function ShowWindow Lib "user32" _
        (ByVal hWnd As Long, _
        ByVal nCmdShow As Long) _
    As Long
#END IF
 

Nightowl4933

Tryin' to do it right...
Local time
Today, 08:03
Joined
Apr 27, 2016
Messages
151
No, that is just an example using another function in user32.dll
I only have a 32bit system, so might be on the wrong path?

Just surround your code with the #VBA7 test?
Try it, what do you have to lose?

I am on Access 2007 and my VBA is 6.5

HTH
Code:
#IF VBA7
Public Declare PtrSafe Function IsWindowVisible Lib "user32" _
        (ByVal hWnd As Long) _
    As Long
Public Declare PtrSafe Function ShowWindow Lib "user32" _
        (ByVal hWnd As Long, _
        ByVal nCmdShow As Long) _
    As Long
#ELSE
Public Declare Function IsWindowVisible Lib "user32" _
        (ByVal hWnd As Long) _
    As Long
Public Declare Function ShowWindow Lib "user32" _
        (ByVal hWnd As Long, _
        ByVal nCmdShow As Long) _
    As Long
#END IF

Thanks, but I don't even know how to 'surround my code with the #VBA7 test' let alone where to do it! :eek: I guess it would be in the same Module as the code? :confused:

Pete
 

Gasman

Enthusiastic Amateur
Local time
Today, 08:03
Joined
Sep 21, 2011
Messages
14,267
Thanks, but I don't even know how to 'surround my code with the #VBA7 test' let alone where to do it! :eek: I guess it would be in the same Module as the code? :confused:

Pete

I've done it for you in the code window?

Replace the similar code that FrothingSlosh supplied with that from the code window of my post.
 

sneuberg

AWF VIP
Local time
Today, 00:03
Joined
Oct 17, 2014
Messages
3,506
If you get this working would you see if you have the same problems that were brought up in this thread where the poster couldn't print reports. It appeared to me that this code just doesn't work in later versions of Access.
 

Nightowl4933

Tryin' to do it right...
Local time
Today, 08:03
Joined
Apr 27, 2016
Messages
151
If you get this working would you see if you have the same problems that were brought up in this thread where the poster couldn't print reports. It appeared to me that this code just doesn't work in later versions of Access.

Will do, but it will be a couple of days I'm afraid. I've got a robing ceremony to go to tomorrow! (It's not me)

Pete
 

Nightowl4933

Tryin' to do it right...
Local time
Today, 08:03
Joined
Apr 27, 2016
Messages
151
I've done it for you in the code window?

Replace the similar code that FrothingSlosh supplied with that from the code window of my post.

OK, I'll give that go - it'll take a couple of days, but I'll get back to you :)

Thank you,

Pete
 

Users who are viewing this thread

Top Bottom