Microsoft

How to use one Access form for multiple tasks


Occasionally, users want to enter new records without wading through existing records. You might think you need two forms, but you might not. If the form’s structure is the same, you can use just one form. For instance, let’s suppose users want to enter new customer records and view existing customer information, but they don’t want to worry about existing data when entering new records.

Instead of creating two dedicated forms for each task, create just one bound Customers form. Then, create a second form and name it Menu. You'll use the Menu form to open the Customers form in data entry or viewing mode, but not both. Add two command buttons to the Menu form and name them cmdEnter and cmdBrowse. Then, launch the Menu form’s module and add the following code:

Private Sub cmdBrowse_Click()

'Open browsing form.

DoCmd.OpenForm "Customers"

Forms!Customers.Filter = vbNullString

Forms!Customers.AllowAdditions = False

Forms!Customers.DataEntry = False

End Sub

Private Sub cmdEnter_Click()

'Open data entry form.

DoCmd.OpenForm "Customers"

Forms!Customers.Filter = vbNullString

Forms!Customers.DataEntry = True

End Sub

Instruct (or force) users to use the Menu form when they need to enter new customers or view existing customer data. When the user clicks cmdBrowse, the Click event will populate the Customers form with the underlying data and disable the New button on the Navigation toolbar. When a user clicks cmdEnter, the Click event doesn't populate the Customers form with any underlying data. Instead, the form displays blank controls and accepts new data.

Depending on your circumstances, you can use a menu-type for to open a form in many different modes.

About

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

0 comments

Editor's Picks