Example Apps for Businesses, Schools & Developers

Click the image to view a larger version

Screenshot

CAI_v3.59

Version 3.61         Last Updated 2 Apr 2022

Section Links:         Introduction         Video         Code         Download         Related Apps

Introduction                                                                                           Return To Top

This example shows how the Access application interface can be controlled in various ways.
Several methods can be used to help make a database more secure.

The example database opens with a form 'floating independently' on the desktop 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)
g)   open another form with a related report.
h)   open a report in report view/dialog mode/as a subform.
i)    open a report in print preview with the print preview ribbon displayed whilst the report is open
      and hidden again when the report is closed
i)    open split forms & navigation forms with the application interface hidden
j)    add rounded corners & fade effects to forms
k)   display a message box with the application interface hidden
l)    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 example is designed to show that all items can be toggled on / off independently without problems.

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

The main code used can be found in the modules:
- modDatabaseWindow/modNavPaneTaskbar/modRibbon/modMoveForm

Some code is standard and widely known e.g. hide navigation pane / ribbon.
However, much of the code is either mine or by other named authors.

This example database also includes:
- code to resize forms for any screen size & resolution in module modResize
- additional functions in modules modDesignFeatures/modFadeForm/modCreateRoundedCorners

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



YouTube Video                                                                                           Return To Top

UPDATE - 28 Dec 2021

I ran a 1 hour session on Controlling the Access Interface and Attention Seeking in Access for the US based Access User Group - Eastern Time on 17 Dec 2021.

The video is now available at the Access User Groups channel on You Tube or you can click on the video below.

       

Many thanks to Crystal Long (MVP) for the significant amount of time she spent expertly editing the video recording of this session.

A slightly modified version of this video is also available from this website with the volume increased.

It can be downloaded directly by clicking this link: Download Video

NOTE: Clicking the link starts a DIRECT download of a zipped MP4 file of around 445MB.



VBA Code                                                                                                       Return To Top

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

CODE:

Option Compare Database
Option Explicit

' 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'A2010 or later (32/64-bit)
   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  'A2007 or earlier
   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


Although very simple, this code works well except for one VERY IMPORTANT issue.

If a user clicks on the Access icon in the taskbar, the application interface is restored.
It is VERY unlikely that this would be desirable behaviour.

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

To overcome this, I now recommend using the following code to hide the application interface

CODE:

Function HideAppWindow(frm As Access.Form)

   'new code - app window is NOT restored when taskbar icon clicked
   'omit the ...Or WS_EX_APPWINDOW ...section if you want to hide the taskbar icon
   SetWindowLong frm.hWnd, GWL_EXSTYLE, GetWindowLong(frm.hWnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW
   ShowWindow Application.hWndAccessApp, SW_HIDE
   ShowWindow frm.hWnd, SW_SHOW

End Function


The above code is then referenced as one line in the Form_Load event.

CODE:

Private Sub Form_Load()

On Error GoTo Err_Handler

       Me.Painting = False   'turn off screen updating temporarily
       HideAppWindow Me 'hide application interface
       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 in forms such as 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' done to show a datasheet view.

To handle this successfully we need to modify the HideAppWindow code to reference the parent form

CODE:

Function HideParentAppWindow(frm As Access.Form)

   'new code - use with split forms
   '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

End Function


The above code is then referenced as one line in the Form_Load event of the split form.

CODE:

Private Sub Form_Load()

On Error GoTo Err_Handler

   'hide application interface    
   'need to hide parent for split form to prevent taskbar icon being hidden
   HideParentAppWindow Me

Exit_Handler:
   Exit Sub

Err_Handler:
   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 when the application interface is hidden.

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 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 and DragFormWindow function.

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

'===================================

Public Function DragFormWindow(frm As Form)

    'Use this function in a form MouseDown event
    With frm
        ReleaseCapture
        SendMessage .hWnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0
    End With

End Function


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
  'move form by dragging
  DragFormWindow Me

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
  'move form by dragging
  DragFormWindow Me

Exit_Handler:
   Exit Sub

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

End Sub




Version History / Download                                                           Return To Top

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 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
v3.48   02/12/2020 - added a summary of the main code used when hiding the application interface
v3.51   02/10/2021 - added support for navigation forms together with form fade and rounded corner effects
v3.57   15/12/2021 - simplified code used with additional functions & updated code blocks above
v3.58   16/01/2022 - improvements to ViewCode feature in example app
v3.60   03/03/2022 - corrected API declaration error in modDatabaseWindow
v3.61   02/04/2022 - corrected declaration error in modNavPaneTaskbar

Click to download:           Control Application Interface            (zipped - approx 2.2 MB)



Related Applications                                                                             Return To Top

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

CODE:

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




Colin Riddington           Mendip Data Systems                 Last Updated 2 Apr 2022



Return to Top Return to Example Databases Page