Mandatory field

J

John

Hi

How can I make a field mandatory on a form such that when a new record is
added user cannot move way until the field is filled and an appropriate
message is displayed if field is left empty?

Thanks

Regards
 
K

Ken Sheridan

Firstly you should set the field's Required property to True (Yes) in table
design. This ensures it cannot be Null however a record is entered.

In a form you can examine the field for Null in the form's BeforeUpdate
event procedure and display a message if necessary. This procedure has a
Cancel argument, so you can also set its return value to True, e.g.

Const conMESSAGE = "A value must be entered in field whatever."

If IsNull([YourField] Then
MsgBox conMESSAGE, vbExcalamation, "Warning"
Cancel = True
End If

Ken Sheridan
Stafford, England
 
J

javier

John said:
Hi

How can I make a field mandatory on a form such that when a new record is
added user cannot move way until the field is filled and an appropriate
message is displayed if field is left empty?

Thanks

Regards
 
R

Richard

Open your table in design view, click on the field want to make mandatory
look at the field properties box. Under the general tab you will see
"required" click yes.
 
K

Ken Sheridan

Missed a closing parenthesis:

If IsNull([YourField]) Then

Ken Sheridan
Stafford, England

Ken Sheridan said:
Firstly you should set the field's Required property to True (Yes) in table
design. This ensures it cannot be Null however a record is entered.

In a form you can examine the field for Null in the form's BeforeUpdate
event procedure and display a message if necessary. This procedure has a
Cancel argument, so you can also set its return value to True, e.g.

Const conMESSAGE = "A value must be entered in field whatever."

If IsNull([YourField] Then
MsgBox conMESSAGE, vbExcalamation, "Warning"
Cancel = True
End If

Ken Sheridan
Stafford, England

John said:
Hi

How can I make a field mandatory on a form such that when a new record is
added user cannot move way until the field is filled and an appropriate
message is displayed if field is left empty?

Thanks

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top