Required Values

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

Guest

On my form I have 2 specific fields, Study Number and Proposal Number, that
are important fields that I want to track. Is there a way to set it up so
the user must add information in at least one of these fileds??? I know how
to set fields as required fields but not to say one of the two are required.
I am assuming that a simple VB If Statement could take care of it but I'm not
sure how to go about it. Any help would be appreciated.
 
Roger,

Access provides a form BeforeUpdate event, called when the user attempts to
move off the record but before the record is saved. You can use this event
to do overall record checking--if both are blank, you can issue a message to
the user, set the Cancel flag, and reset the focus to either field.
Something like:

If (Nz(Me![Study Number]) = 0 AND Nz(Me![Proposal Number]) = 0) Then
MsgBox "Either a Study Number or Proposal Number is required.", _
vbOKOnly, "Blank Required Field Detected"
Cancel = True
Me![Study Number].SetFocus
End If

Hope that helps.
Sprinks
 
Roger

One approach would be to add an event procedure to the form's BeforeUpdate
event. In that procedure, you would check to see if both were still null,
and if so, cancel the update, along with a message to let the user know.
You could also set the focus back to the first of the two controls. The
following is untested aircode:

If IsNull(Me!MyFirstControl) and IsNull(Me!MySecondControl) Then
Cancel = True
MsgBox "You need to fill one of these..."
Me!MyFirstControl.SetFocus
End If
 
Back
Top