Question Locked

Highlight required fields ?Code not working

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hallo
The following link/ article recommends putting code both in the On Current Property and the After Update Event Property. The code is the same for both properties. It should highlight the required field while it is empty and then the background colour should revert back to white when data have been entered.

I copied the code (shown below) as is. Unfortunately, the required field stays red even after data have been entered.

I understand so little about code that I have no idea how to make this work as planned. Any suggestions ?

The link: http://www.techonthenet.com/access/forms/change_bg.php

The recommended code:
If IsNull(ContactTitle) = True Then
ContactTitle.BackColor = vbRed
Else
ContactTitle.BackColor = vbWhite
End If

ALSO, this code seems to be good only for one field ? I have several required fields. Could I replace ?ContactTitle? from the sample with a string of (Field1;Field2;Field3; .. etc.)? Do I use commas, semicolons or colons as separators ?

2 replies

by tony hopkinson

That's a bit naughty

Is ContactTitle the column, or the TextBox?

Try giving your textboxes a prefix e.g. tb_ or somesuch.

I would have expected the IsNull test to be on the column, but checked on a new record (Form_Current) or a change tb_MyColumn_AfterUpdate.

As for doing more than one test,

In Form Current it would be

If ISNull(Column1)...

If IsNull(Column2)...

and thene an After_Update event handler for each text box.

HtHs

This discussion is closed to new replies.