Mandatory Fields

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

Guest

I’m trying to create an Access form that, when a person checks an ‘unable to
determine’ checkbox, Access will prevent the user from proceeding with the
form until they explain in an adjacent text box why they selected ‘unable to
determine’. If the user selects from the other two options (yes or no), they
do not need to fill out the text box.

Any ideas (hopefully an easy solution!)?

Thanks!
 
This can be done, but I recommend against it. What if the person selects the
option by mistake then tries to change it to Yes or No? You have now
prevented them from doing anything except filling in the textbox, which is
actually no longer applicable because they are trying to choose Yes or No.
Yes, the could press Esc to cancel the record, but then they get to start
all over again.

The best way is to make them fill in the textbox prior to saving the record.
To do this, use the form's BeforeUpdate event. Check the value of the option
and if it is the "unable..." option, check the value of the textbox to see
if an entry has been made. If not, Cancel the update, use a MsgBox to advise
the user of the problem, and set the focus to the textbox.
 
Thanks for the help Wayne.

Do you have sample code for this? I've been experimenting a bit, but can't
seem to get it to work.

Thanks!

-Manny
 
In the form's BeforeUpdate event:

If Me.optDetermination = 3 Then
'assuming an Option Group was used
If Nz(Me.txtReason, "") = "" Then
Msgbox "You need to specify a reason", vbOkOnly + vbExclamation,
"Missing Info"
Cancel = True
Me.txtReason.SetFocus
End If
End If
'Other checks here as needed
 
Amend the previous sample slightly:
If Me.optDetermination = 3 Then
'assuming an Option Group was used
If Nz(Me.txtReason, "") = "" Then
Msgbox "You need to specify a reason", vbOkOnly + vbExclamation,
"Missing Info"
Cancel = True
Me.txtReason.SetFocus Exit Sub
End If
End If
'Other checks here as needed
 
Back
Top