How to hide Access from the user

Microsoft Access is at heart a database for users. It provides a lot of useful features so that the average user can work with their database by just selecting a menu option or clicking a button on the toolbar. Sometimes though you want to remove these features so that your application has a cleaner interface and the user can focus on the controls that you have provided.

You may want to hide the database window so that your form is all that's visible on screen or you might want to go further and hide everything except your main form.

Hide the Access Database Window

[Hide the Access window at startup] Hiding the Database Window from the user is easy. You just set it as one of the Access startup options by selecting Startup... from the Tools menu and then removing the tick from the Display Database Window tickbox as shown in the screenshot opposite.

This still leaves the user able to press F11 to restore the Database Window. You need to suppress this as well by clearing the Use Access Special Keys tickbox. This is on the Advanced section of the startup options dialog.

Hide the Database Window in code

If you want more control over the behaviour of the window - perhaps you want to hide it from most users and just show it to the administrator - you can hide the window with some VBA code:

DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide

The first line here sets focus to the Database Window by specifically asking to select the Table pane from that window. This forces the Database Window to be the current window and the second line then hides that window.

Hide Access from the user completely

[Hiding Microsoft Access altogether] This trick is more difficult but it is still possible. The screenshot opposite shows an Access form floating on top of the Windows desktop with no sign of the main Access window. The only clue telling us that this is Access is the fact that there's an Access form icon in the title bar. With a little more effort I could have changed that icon and made this look like a real Windows application rather than "just" another Access database.

This switchboard is the first form that will appear when the user opens the database but it is not the main form of the application. There is another form and this is where the work is being done. Its only job is to make a call to the Windows API when it opens.

There are no controls on this form and the user will never see it but it must have two of its properties set:

Pop Up: Yes
Modal: No

It must also be set as the main form of the database in the Access start up options.

VBA program code

There are four pieces of VBA code required to make this work. Three are in the first form:

1. Declare the Windows API call:

'-- Constants used by ShowWindow
Const SW_HIDE = 0
Const SW_NORMAL = 1
Const SW_MINIMIZED = 2
Const SW_MAXIMIZED = 3

Private Declare Function ShowWindow Lib "user32" _
  (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

2. Make the call to hide the whole Access window and then open the main form for the user:

Private Sub Form_Open(Cancel As Integer)
   Call ShowWindow(hWndAccessApp, SW_HIDE)
   DoCmd.OpenForm "Switchboard", windowmode:=acDialog
End Sub

3. Reset the Access window when the application closes:

Private Sub Form_Unload(Cancel As Integer)
Dim lngRetCode As Long
   lngRetCode = ShowWindow(hWndAccessApp, SW_MAXIMIZED)
End Sub

There is one last piece of code to be added but this must be added to the user's form rather than to the hidden startup form. It's needed so that Access will close when the user closes their main form. The technique will appear to work without this last bit of code but what you won't see is that Access itself will still be running. We have to make sure that Access will be closed down when the user closes the form and the way to do it is to add this line to the Unload event of the switchboard form:

Private Sub Form_Unload(Cancel As Integer)
   Application.Quit
End Sub

Stop Press

This last technique does not work with Access 2007 under Windows 7. I was planning to work through this web site, replacing the old Access 2000 and Access XP screenshots with some nice new Access 2007 images, but when I tried to run this example I found that the code was ignored and the form just opened as normal in the Access window.

Just another little niggle to be fixed when upgrading to the new version.

Access Tips

FoxPro Tips

General Tips

 

Related Items

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

Custom Toolbars

Your Access database will look more impressive if you add custom toolbars.

Read More

Development Services

Alvechurch Data specialise in Microsoft Access and Visual FoxPro databases and have fifteen years experience developing databases for small business use.

Read More

Access and Visual FoxPro Training

Microsoft Access and Visual FoxPro training courses and workshops offered by Alvechurch Data in Birmingham.

Read More

Support Services

How Alvechurch Data can help you with maintenance and support of your Access and FoxPro databases.

Read More