Make form field required

G

Guest

Greetings,

I have several fields on a form that need to be required and not permit the
user to leave blank Therefore, I need the user to make a selection from the
dropdown list.

p.s., I've tried to adjust the respective field properties (required, Val
Rule/Text) in both the table/form. However, when I use the table's field
properties...I don't get the validation text that I'd like...I get the
computers standard blah, blah, blah...when I use the form's field
properties...the user is able to skip right past the required field...(that
being said, if they tab into the field then my desired validation text pops
up)...but I can't allow them to just skip it...

Hope I communicated my situation clearly...it seems to be more clear in my
head then when I see it on the screen in front of me....

Any help would be appreciated....

v/r
Steve
 
A

Allen Browne

Steve, open your table in design view, and select the field.
Instead of setting its Required property in the lower pane of table design,
set:
Validation Rule: Is Not Null
Validation Text: Oops: Ya need ta enter MyField.

If you really want to do it a the form level instead (e.g. if you want the
user to be able to override the warning and leave it blank anyway), use the
BeforeUpdate event of the *form* to see if the control is null:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If IsNull(Me.[SomeField]) Then
strMsg = "SomeField is still blank." & vbCrLf & _
" Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) = vbNo Then
Cancel = True
End If
End If
End Sub
 
G

Guest

Thank you...that took care of it...

Allen Browne said:
Steve, open your table in design view, and select the field.
Instead of setting its Required property in the lower pane of table design,
set:
Validation Rule: Is Not Null
Validation Text: Oops: Ya need ta enter MyField.

If you really want to do it a the form level instead (e.g. if you want the
user to be able to override the warning and leave it blank anyway), use the
BeforeUpdate event of the *form* to see if the control is null:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If IsNull(Me.[SomeField]) Then
strMsg = "SomeField is still blank." & vbCrLf & _
" Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) = vbNo Then
Cancel = True
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Shek5150 said:
Greetings,

I have several fields on a form that need to be required and not permit
the
user to leave blank Therefore, I need the user to make a selection from
the
dropdown list.

p.s., I've tried to adjust the respective field properties (required, Val
Rule/Text) in both the table/form. However, when I use the table's field
properties...I don't get the validation text that I'd like...I get the
computers standard blah, blah, blah...when I use the form's field
properties...the user is able to skip right past the required
field...(that
being said, if they tab into the field then my desired validation text
pops
up)...but I can't allow them to just skip it...

Hope I communicated my situation clearly...it seems to be more clear in my
head then when I see it on the screen in front of me....

Any help would be appreciated....

v/r
Steve
 
A

Al Camp

Steve,
The Required property won't monitor whether you entered data or not until
the record is updated. For example when you try to leave the record, or do
a Refresh. If a field is defined as required in your table design, you can
not leave the record until an entry has been made.
If you need a more "immediate" warning, try using the Exit event of the
field...

Private Sub YourField_Exit(Cancel As Integer)
If IsNull(YourField) Then
Beep
MsgBox "This field must contain an entry.", vbOKOnly, "Entry
Required"
Cancel = True
End If
End Sub

This assumes the user will tab through the field. If they don't, then
the "Required" property will pick up the problem when the record tries to
update.
 
G

Guest

Thank you Al...

Al Camp said:
Steve,
The Required property won't monitor whether you entered data or not until
the record is updated. For example when you try to leave the record, or do
a Refresh. If a field is defined as required in your table design, you can
not leave the record until an entry has been made.
If you need a more "immediate" warning, try using the Exit event of the
field...

Private Sub YourField_Exit(Cancel As Integer)
If IsNull(YourField) Then
Beep
MsgBox "This field must contain an entry.", vbOKOnly, "Entry
Required"
Cancel = True
End If
End Sub

This assumes the user will tab through the field. If they don't, then
the "Required" property will pick up the problem when the record tries to
update.
--
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions
 

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