Mendip Data Systems

Database applications for businesses and schools

LogoTransparent

Control the Application Interface

Version 3.47    Updated 02/12/2020      (to include a summary of code used)        

 

This example shows how the Access application interface can be controlled in various ways

Some of these methods can be used to help make a database more secure.

 

The database is opened with a form 'floating independently' on the desktop i.e. with the access application window hidden

 

Buttons on the form can be used to:  

a)   drag a borderless form to a new position

b)   show / hide entire Access application window

c)   show / hide navigation pane

d)   show / hide ribbon

e)   show / hide taskbar

f)   maximise the form to fill the entire screen (no title bar & no taskbar) - this only works for a popup form

g)   open another form with a related report.

h)   open a report in report view/dialog mode/print preview. The last method shows how the print preview

     ribbon can be displayed whilst the report is open & the ribbon hidden again when it is closed

i)    open a split form with the application window hidden

j)    open / close the Visual Basic Editor (VBE)

 

Although it is highly unlikely that any single application would need to use all of these features, this is designed to show that all items can be toggled on / off independently without problems.

 

All code has been fully tested in Access 2010 & 365 (32-bit & 64-bit) and has been widely used in various production databases for several years.

 

The code used can be found in the modules:

  • modDatabaseWindow / modNavPaneTaskbar / modRibbon

 

Some of the code is widely known e.g. hide navigation pane / ribbon.

Other parts are written by myself or other authors. Where appropriate, those authors have been acknowledged.

 

This example database also includes:

  • code to resize forms for any screen size & resolution in module modResize

  • additional functions in module modDesignFeatures

 

If you wish to use any of the code in your own projects, just copy the relevant module code including all author information as supplied.

Click the image to view a larger version ...

Screenshot

Return to Example Databases Page

Example Apps for Businesses, Schools & Personal Use

RELATED APPLICATIONS

 

Here are several more variations which were suggested by various Access forum members but which may be useful to others. Each should work in both 32-bit & 64-bit Access

 

 

1. Title Bar Only 

This was requested by Utter Access member tina_t via a private message

The OP wanted the application window to be retained but with the title bar only - no nav pane or ribbons:

 

i) This approach works best with overlapping windows.

ii) The form MUST be a popup

 

Click to download:           TitleBarOnly                      Approx 0.5 MB (zipped)

 

 

 

2. Modal forms

This was written in response to a very old thread at Access World Forums where AWF member tonyluke had  issues using modal forms when the application window was hidden. As stated in that thread, doing an action such as transfer database with

a modal form running will make the navigation pane visible if it was hidden.

 

For most purposes, this is useful behaviour so you can check if the action has worked

But where you need it to remain hidden, you can use code to hide the nav pane again immediately

 

However this behaviour won't occur if you also hide the entire application window

 

The example FE/BE databases attached should be saved in the same folder

The BE just has a dummy table to test for linking

The FE contains a modal form with the application window hidden by default

 

i) Click the Link Table button - the nav pane remains hidden

   Click the button again to delete the linked table

ii) Click the Show Navigation Pane button then click the Link Table button

 

Click to download:           TestModal                         Approx 1 MB (zipped)

 

   

 

3. Remove Title Bar Buttons 

Requested by Access World Forums member joeyd11ph in the thread Shutdown PC through Access button

 

The OP wanted all buttons removed from the title bar in order to control Access closedown via code only.

 

i) This approach only works with overlapping windows.

ii) The form MUST be a popup with NO control box, close, max/min buttons

iii) To remove the title bar as well, set form border style to None

 

Click to download:          RemoveTitleBarButtons    Approx 0.5 MB (zipped)

 

 

In addition, he wanted to know how to do other actions such as log off or shut down the PC completely using VBA for which I supplied the following code. Place it in a standard module

Option Compare Database

Option Explicit

 

'NOTE switches used below

/s = shutdown

/r = reboot

/l = logoff

/f = force apps to close without warning

/t xxx = time delay of xxx seconds e.g. /t 2

 

' ‘*******************SHUT DOWN*********************

Public Function TurnOff()

   

   Shell "shutdown /s /t 2", vbHide

   Application.Quit

End Function

 

' ‘*********************REBOOT***********************

Public Function Reboot()

   Shell "shutdown /r /t 2", vbHide

   Application.Quit

End Function

 

' ‘*********************LOG OFF***********************

Public Function LogOff()

   'omit /t switch or it doesn't work

   Shell "shutdown /l", vbHide

   Application.Quit

End Function

 

'‘**********************FORCE************************

Public Function ForceReboot()

   Shell "shutdown /r /f /t 3", vbHide

   Application.Quit

End Function

 

SetWindows_v3.47

UPDATES:

v2.0     09/05/2018 - added code to shows ways of running a query with the application interface hidden

v3.0     02/01/2019 - added code to open a report with the application interface hidden

v3.2     13/02/2019 - fixed an issue in 64-bit Access

v3.3     04/04/2019 - added code to allow form to be dragged using mouse down event

v3.41   19/07/2019 - modified code to prevent application window being restored after clicking on taskbar icon

v3.44   14/08/2019 - various bug fixes related to code in previous update

v3.46   14/01/2020 - added additional methods of handling reports when application window is hidden

v3.47   31/10/2010 - added code to manage use of Access split form when application window is hidden

          02/12/2020 - added a summary othe main code used when hiding the application interface

 

 

     

Click to download:          SetWindows v3.47            (zipped - approx 2.2 MB)

The module modDatabaseWindow contains API declarations and functions used to manage the application interface

 

Code:

Option Compare Database

Option Explicit

 

'************ Code Start **********

' This code was originally written by Dev Ashish.

' It is not to be altered or distributed,

' except as part of an application.

' You are free to use it in any application,

' provided the copyright notice is left unchanged.

'

' Code Courtesy of Dev Ashish

 

'Additional API code by Daolix

 

'/* ShowWindow() Commands */

 

Global Const SW_HIDE = 0

Global Const SW_SHOWNORMAL = 1

Global Const SW_SHOWMINIMIZED = 2

Global Const SW_SHOWMAXIMIZED = 3

 

Global Const SW_SHOW = 5

 

Public blnShowWindow As Boolean

 

'###############################################

#If VBA7 Then

   Declare PtrSafe Function ShowWindow Lib "user32" _

       (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long

       

   Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _

       (ByVal hWnd As LongPtr, ByVal nIndex As Long) As Long

           

   Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _

       (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

   

   Declare PtrSafe Function GetParent Lib "user32" _

       (ByVal hWnd As LongPtr) As LongPtr

       

#Else  '32-bit Office

   Declare Function ShowWindow Lib "user32" _

       (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

       

   Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _

       (ByVal hWnd As Long, ByVal nIndex As Long) As Long

           

   Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _

       (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

       

   Declare Function GetParent Lib "user32" _

       (ByVal hWnd As Long) As Long

#End If

'###############################################

       

'/* Window field offsets for Set/GetWindowLong() */

Public Const GWL_EXSTYLE       As Long = -20

 

'/* Extended Window Styles */

Public Const WS_EX_APPWINDOW   As Long = &H40000

 

Function SetAccessWindow(nCmdShow As Long)

 

   'Usage Examples

   'Maximize window:

   ' ?SetAccessWindow(SW_SHOWMAXIMIZED)

   'Minimize window:

   ' ?SetAccessWindow(SW_SHOWMINIMIZED)

   'Hide window:

   ' ?SetAccessWindow(SW_HIDE)

   'Normal window:

   ' ?SetAccessWindow(SW_SHOWNORMAL)

   

   Dim loX As Long

  ' Dim loForm As Form

   On Error Resume Next

   

   loX = ShowWindow(hWndAccessApp, nCmdShow)

   SetAccessWindow = (loX <> 0)

 

End Function

 

Function RestoreNormalWindow()

 

   SetAccessWindow (SW_SHOWNORMAL)

End Function

 

Function MinimizeWindow()

   'You can use this in the form load event of your startup form or in an autoexec macro

   SetAccessWindow (SW_SHOWMINIMIZED)

End Function

IMPORTANT:

When hiding the application interface, all forms MUST be set as popup so these appear independently of the rest of the application interface that you are hiding

 

The simplest method of hiding the application interface is to use the following code in the Form_Load event of your forms. The code includes error handling (this is strongly recommended for all procedures)

 

Code:

Private Sub Form_Load()

 

On Error GoTo Err_Handler

 

   SetAccessWindow (SW_SHOWMINIMIZED)

 

   DoCmd.Restore

   

Exit_Handler:

   Exit Sub

 

Err_Handler:

   MsgBox "Error " & Err.Number & " in Form_Load procedure : " & Err.description

   Resume Exit_Handler

   

End Sub

This code works well except for one important issue.

 

If a user clicks on the Access icon in the taskbar, the application interface is restored.

You can see this in action in the form frmFormQuery supplied with the example app.

 

Whilst it is possible to remove the taskbasr icon, there is a better approach

 

To overcome this, I now recommend using the following code in the Form_Load event.

 

Code:

Private Sub Form_Load()

 

On Error GoTo Err_Handler

 

       'hide application interface

       Me.Painting = False   'turn off screen updating temporarily

       'omit the ...Or WS_EX_APPWINDOW ...section to hide the taskbar icon

       SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW

       ShowWindow Application.hWndAccessApp, SW_HIDE

       ShowWindow Me.hWnd, SW_SHOW

       

       Me.Painting = True    'turn on screen updating again

 

   DoCmd.Restore

   

Exit_Handler:

   Exit Sub

 

Err_Handler:

   MsgBox "Error " & Err.Number & " in Form_Load procedure : " & Err.description

   Resume Exit_Handler

   

End Sub

The code above is used the forms frmStart and frmAccessErrorCodes in the example app.

 

The code works perfectly for all types of Access form except the special case of an Access split form.

Split forms are actually a single form with some backstage 'trickery' used to also show a datasheet view.

 

To handle this successfully we need to reference the parent form in the Form_Load event

 

Code:

Private Sub Form_Load()

 

On Error GoTo Err_Handler

 

   'hide application interface    

   'need to use GetParent(Me.Hwnd) for split form to prevent taskbar icon being hidden

   SetWindowLong GetParent(Me.hWnd), GWL_EXSTYLE, GetWindowLong(GetParent(Me.hWnd), GWL_EXSTYLE)

   ShowWindow GetParent(Me.hWnd), SW_SHOW

 

Exit_Handler:

   Exit Sub

 

Err_Handler:

   strProc = "Form_Load"

   MsgBox "Error " & Err.Number & " in Form_Load procedure : " & Err.description

   Resume Exit_Handler

   

End Sub

This code has been used in the example form frmAccessErrorCodesSplitView in the example database

 

NOTE:

As an alternative to the built-in split form, you could instead use the Emulated Split Form which can be treated like any other standard Access form when hiding the application interface

Reports cannot be managed in the same way as forms. For example, users need a way of printing the report

The application includes several methods of displaying reports in this situation.

 

These include:

a)   using report view and including a Print button on the report itself

b)   using print preview with the print preview ribbon restored whilst the report is open and hidden again on  

     close. Doing this gives additional functionality including the option to save as PDF (etc).

Borderless forms work particularly well for a clean interface when the Access application window is hidden.

However as borderless forms have no title bar, they cannot normally be moved on the screen.

 

The example app includes code to solve this by dragging the form with the left mouse button held down.

The module modMoveForm contains the following API declaration

 

Code:

Option Compare Database

Option Explicit

 

'API to move a form with a mouse down event

 

Public Const WM_NCLBUTTONDOWN = &HA1

 

Public Const HT_CAPTION = &H2

 

#If VBA7 Then

   Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, _

       ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr

   

   Public Declare PtrSafe Function ReleaseCapture Lib "user32.dll" () As Long

#Else

   Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _

       ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

   

   Public Declare Function ReleaseCapture Lib "user32.dll" () As Long

#End If

To use this API code, add code to the mouse down event in the form header and/or a command button.

The following code is included in the main form frmStart in the example application.

 

Code:

Private Sub FormHeader_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

 

On Error GoTo Err_Handler

 

  X = ReleaseCapture()

  X = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0)

 

Exit_Handler:

   Exit Sub

 

Err_Handler:

   MsgBox "Error " & Err.Number & " in FormHeader_MouseDown procedure : " & Err.description

   Resume Exit_Handler

   

End Sub

 

 

Private Sub lblHeader_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

 

On Error GoTo Err_Handler

 

  X = ReleaseCapture()

  X = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0)

 

Exit_Handler:

   Exit Sub

 

Err_Handler:

   MsgBox "Error " & Err.Number & " in "lblHeader_MouseDown procedure : " & Err.description

   Resume Exit_Handler

   

End Sub