Force data entry of a combo box or a check box

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

Guest

I have a form where I want to make it so either a combo box is populated or a
check box is checked before leaving the form.
Is there any way to do this?
It needs to be one or the other, not both.

Thanks,
Tammy
 
Hi, Tammy.

In the form's OnBeforeUpdate( ) event, try:

Private Sub Form_BeforeUpdate(Cancel As Integer)

On Error GoTo ErrHandler

If ((Nz(Me!cboDept.Value, "") = "") And _
(Nz(Me!chkDone.Value, 0) = 0)) Then
Cancel = True
MsgBox "Please select a department or" & vbCrLf & _
"mark the check box.", _
vbCritical + vbOKOnly, "Can't Continue!"
End If

Exit Sub

ErrHandler:

MsgBox "Error in Form_BeforeUpdate( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

.. . . where cboDept is the name of the combo box and chkDone is the name of
the check box. If the user tries to close the form before either of these
two items is taken care of, the user will be warned that the record will not
be saved and will be offered the opportunity to return to the form for
further editing or close the form without saving the record.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Back
Top