How to Highlight Required Fields and Controls with Focus in MS Access

In this article, we understand how to highlight just the required fields and controls that have focus in MS Access.

Automatically highlighting a field that needs an entry, or a control with focus, so that you don’t waste time locating the cursor probably sounds too good to be true right? But it’s not, you cannot only wish to implement these utilities but also be able to implement them in reality by following a few simple steps.

Today we will be explaining you about this utility that you can implement in any form that is in the Form view, by setting just one property. Highlighting Required Fields And Controls With Focus In MS Access

Implementation

Let us say you are working on a form and want to highlight the ‘Title’ as the current field, and the remaining fields as required, with a particular background and formatted text. For the implementation of this, you need the following:

  1. An example database (download it).
  2. From the example database, copy the module that has ‘highlight’ in it, and paste it in your database.
  3. Widen all the labels that are attached to the controls. This will make the text bold, along with adding a star.
  4. Set the ‘On Load’ property of the form to: =setupForm ([Form])

Note: the ‘[Form]’ shown here needs to be used in the exact same way and does not have to be replaced by your form name.

Expressions Required

Highlighting Required FieldsAfter following the basic implementation procedure, we now need to add relevant expressions for the kind of changes we are looking at. Make use of the following expression according to your needs

Highlighting required fields only

=SetupForm([Form], 1)

Highlighting only the controls with focus.

=SetupForm([Form], 2)

* If the On Load property of your form has been set to [Event Procedure], you should opt for adding the following line in your code.

Call SetupForm(Me)

Changing color schemes

You can opt for highlighting the fields by changing the color schemes, this will require you to assign different values to all the constants that are located at the module top. ‘mlngcFocusBackColor’ is used for defining the color for the control that has focus.

mlngcFocusBackColor is used for defining the color of the fields that require an entry.

While you are opting to make changes in the color scheme, you should keep the following points in mind.

  • Only the asterisk will appear in the Datasheet view (over column headings).
  • Only the background color will show in a continuous form (here you might have missed out on attaching labels).
  • If you wish to bold the labels in Form Header, you should use the CaptionFromHeader() function.
  • If the labels are not attached to the controls you will not be able to make them bold or add a star mark.

Limitations

  1. The above-defined process/code can be used only for highlighting combo boxes, text boxes, and list boxes.
  2. If there is already something present on the ‘On Lost Focus’ and the ‘On Got Focus’ properties of the control, it will not be able to highlight.

As a regular user of MS Access, you may have at times encountered an incident of Access corruption. To deal with these scenarios one must consider keeping a state of the art Access repair tool like DataNumen Access Repair handy. In the event of a crash this powerful tool can ensure that every record stored in your Access database is brought back in perfect shape.

Author Introduction:

Vivian Stevens is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql recovery and excel recovery software products. For more information visit www.datanumen.com

One response to “How to Highlight Required Fields and Controls with Focus in MS Access”

Leave a Reply

Your email address will not be published. Required fields are marked *