Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
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
Hiding the Database Window from the user is easy. You just set it as one of the Access startup options by selecting from the menu and then removing the tick from the tickbox as shown in the screenshot opposite.
This still leaves the user able to pressto restore the Database Window. You need to suppress this as well by clearing the 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:
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
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:
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:
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:
Call ShowWindow(hWndAccessApp, SW_HIDE)
DoCmd.OpenForm "Switchboard", windowmode:=acDialog
3. Reset the Access window when the application closes:
Dim lngRetCode As Long
lngRetCode = ShowWindow(hWndAccessApp, SW_MAXIMIZED)
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 theevent of the switchboard form:
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.