Hide access window when opening a form

This is the code I run in my Acc 2003 and 2007 Apps, running in 2010 environment:

Private Sub Form_Load()
   'Hide Data-Base Window:
   DoCmd.SelectObject acTable, , True
   DoCmd.RunCommand acCmdWindowHide
  '...Other Actions...
end sub

For hiding the ribbon in 2007 and higher use this line I found here:

DoCmd.ShowToolbar "Ribbon", acToolbarNo

It seems your goal is to restrict the Access UI features which are available to the user of your database. You want to limit them to the options which you provide via your startup form.

In that case, take a copy of your ACCDB file and change its file extension to ACCDR. Then when you open the ACCDR from Windows Explorer, Access will open it in "runtime mode". Runtime mode suppresses most of the standard UI options. For example, the Navigation pane is not displayed, and can't even be opened. Also it gives you a very minimal version of the Ribbon; the majority of the standard Ribbon options are gone.

Runtime mode has other consequences which you should investigate to see whether it's a good fit for your needs. One important issue is runtime mode will quit the application when an unhandled error is encountered.

If ACCDR/runtime mode suits your particular situation, it is an inexpensive way to limit the database UI features. However, beware a user could make a copy of the ACCDR and change the file extension back to ACCDB, so this approach alone may not satisfy your security requirements.


This is what I use that works up to 2016:

Option Compare Database
Option Explicit

'''HIDE WINDOW MODULE
'''USE THIS TO ACTIVATE HIDE WINDOW MODULE
''' SixHatHideWindow(SW_SHOWMINIMIZED)

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 SixHatHideWindow(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
    SixHatHideWindow = (loX <> 0)
End Function

To Hide the Window Simply: Call SixHatHideWindow(SW_SHOWMINIMIZED)

ALSO NOTE: Depending on Which Version i.e. 32 bit or 64 bit you may need to add the PtrSafe attribute so If you are having issues with this Declare the API Function like this: Private Declare PtrSafe Function apiShowWindow...

Tags:

Ms Access

Vba