Blanks in Fields is a NO! NO! how do I stop it?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All,

I am currently working on a Form and need it to force the users to fill the
fields required and not skip them. I have a Wide array of field types (Text,
Dates etc) but I just cannot get The Validate to work on both the Form and
the Tables. Am I doing something wrong?

- The Novice
 
Hi, TwinDad.

I like to enforce form-wide entry, both for Nulls and for any dependencies
of one field on another is with the form's BeforeUpdate event, which is
triggered just before the user attempts to leave the current record. Access
provides the Tag property for each form control. For all required controls,
enter a non-null value in this property, such as "R".

Then, in the BeforeUpdate event procedure, scan all of these fields and
ensure they are not null. If they are, stop and set the focus to the
offending control.

Dim ctl as Control
For Each ctl in Me.Controls
If ctl.Tag = "R" Then
If Nz(ctl.Value)=0 Then
MsgBox "The " & ctl.Name & "field is required. Please enter
a value."
ctl.SetFocus
Exit For
End If
End If
Next ctl

Hope that helps.

Sprinks
 
There is a very simple way to mark fields as required, without any code at
all:

1. Open your table in Design view.

2. Select the first field where an entry is required.

3. In the lower pane, set the Required property to Yes.

4. Repeat for the other fields where an entry is required.

While you are doing that, I would also encourage you to set the Allow Zero
Length property to No for all text fields, memos, and hyperlink fields. This
will prevent zero-length strings in the fields, as well as nulls. (Access 97
and earlier did this by default, but in Access 2000 and later you have to
set the property for every field yourself.)

You certainly will not want all fields marked as required. If you were
doing that, it probably means you are having difficulty in handling nulls,
so this article might help:
Nulls: Do I need them?
at:
http://allenbrowne.com/casu-11.html
 
Back
Top