Click here for great value web hosting.

ALL ABOUT OFFICE

HOME

ACCESS

EXCEL

WORD

OUTLOOK

POWERPOINT




Search for
 

help


ACCESS

Creating a Menu Form

A nice way to make use of forms is to create a menu containing buttons which you can click to enter other forms and queries.  If you set this form as your startup form then it will appear as soon as the database is opened.

To create a menu form, it is best to use Design view.  When you have started a new form in Design view you will see a screen like the one below.

Notice the toolbox which appears, if you want to know what each tool is you can hold your cursor over the icon and a description will appear.  We are going to use the Command Button control to put some buttons on our menu which will launch other forms and queries.

To add a button, click on the Command Button control icon on the toolbox and you will see your cursor change.  Click on the grey area of the form and drag out a rectangle for your button as shown below, you can always resize it later if necessary.

As soon as you have dragged out the button you will see the window below appear.

We have chosen the Form Operations category and the Open Form action as we are going to use this button to open our Employees form.  When you have highlighted the actions you want to perform, click the Next button and you will see the window below.

Choose the form you want to open and click the Next button to proceed to the window below.

This window gives you the chance to open the form with all the records or to filter out certain records.  You will not be able to use the first option unless you are able to link records in your forms, we just want to open the whole form.  When you click the Next button you can choose whether you button has a text description on it or a picture as below.

We have put the text 'Employees' on our button.  Click the Next button and you can give your button control a name as below.

Click the Finish button and you will see the completed button on your form.

If you want to see the code behind this button, click your right mouse button on the object and choose Properties from the menu which appears.  Click on the Event tab of the Properties window and you will see the information below.

Click your cursor on the On Click line and then click the box containing three dots to see the code of the Event Procedure.  This is the code of this procedure:

    Option Compare Database

    Private Sub Employeeformbutton_Click()
    On Error GoTo Err_Employeeformbutton_Click

        Dim stDocName As String
        Dim stLinkCriteria As String

        stDocName = "Employees"
        DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Employeeformbutton_Click:
        Exit Sub

    Err_Employeeformbutton_Click:
        MsgBox Err.Description
        Resume Exit_Employeeformbutton_Click
        
    End Sub

This will open the Employees form to display one record at a time.  If you want to open the Employees form in Datasheet view so that you can see all the Employees at once you need to change the DoCmd OpenForm as follows:

        stDocName = "Employees"
        DoCmd.OpenForm stDocName, acFormDS, , stLinkCriteria

Notice the acFormDS parameter which has been added, this forces the form to open in Datasheet view.

Close the Visual Basic window and then close the Properties window.  Save your form by clicking the floppy disk Save icon and you will be asked for a name as below.

Your menu form is now finished.  If you want to set this form as your startup form click here to see how to enter the Startup settings.

Click here to return to the Access index.

webmaster@allaboutoffice.co.uk