Friday 27 April 2012

Hiding the Navigation Pane with VBA

Once you have created an Access Database Application to be used by other people, it may well be important for you to prevent users from gaining access to any of its design features.  By this I mean, you may not want users to modify your tables, forms and queries etc in design view (inadvertently or otherwise).  There are a number of measures you need to take in order to secure your database against this possibility.  One of these involves preventing users from accessing the NAVIGATION PANE, a major doorway to all of your database objects.  Hiding the NAVIGATION PANE can be done with a couple of lines of VBA Code.

To use this code, you will need one of your database forms' to open automatically as your application opens. There are instructions to do this in my post on How to Display a Form Automatically. Once this is in place you can insert the following code into that form's ON LOAD event.

    DoCmd.SelectObject acTable, "tblCustomer", True
    DoCmd.RunCommand acCmdWindowHide 


The purpose of the first line of code is to select any object in the navigation pane.  We have selected one of the database tables called tblCustomer, and then set the INNAVIGATIONPANE parameter to true.  Once  a database object from the navigation pane has been selected, we can then use the DoCmd.RunCommand with the acCmdWindowHide parameter in the following line of code.  This has the effect of hiding whichever window happens to contain the selected object. 

The user can quite easily get the Navigation Pane back by pressing the F11 Access Special Key (assuming  that he or she knows about it), but this facility can be disabled.  To do this you will need to deselect the USER ACCESS SPECIAL KEYS check box in the CURRENT DATABASE section of ACCESS OPTIONS, (via the OFFICE button).

Hiding the Navigation Pane alone is not sufficient to secure a database, but it is one important part of doing so.