Enabling one field from another

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

Guest

I would like to apply two conditions to a check box on a form.

1. A date field I have on the form should become active when a check box is
selected. If there is no check in the check box, then I want the date field
to be disabled.

2. If there is a check in the check box, then I don't want to be able to
move to another field on the form until a date is entered in the check box.
 
In the After Update event of your checkbox:

If Me.chkBox = True Then
Me.txtBox.Enabled = True
Else
Me.txtBox.Enabled = False
End If

In the Lost Focus event of the textbox:

If IsNull(Me.txtBox) Or Me.txtbox = "" Then
Cancel = True
MsgBox "A Date is Required"
End If
 
On the after update event of the checkbox you should write

If me.CheckBox = True then
me.dateField.Enabled = True
me.dateField.setfocus
else
me.dateField.Enabled = False
End If

Call this sub (the after update event from above) on the on current event of
the form, that way the date field will be updated when you move from one
record to another.

==================================
Secnd question
On the on exit event of the date field enter the code

If isnull(me.dateField) then
msgbox "Must enter date"
cancel = true
End if

I must warn you, if the user will select true on the check box, and will be
move to the date field, he wont be able to move back to the check box to
select False if he changed his mind.
So you better check the value of the date on the before update event of the
form and not of the field, that way the user wont be able to move to the next
record, or close the form until the date is entered, that way the user can
still change his mind and unselect the checkbox.

In that case enter the code
If me.CheckBox = True And isnull(me.dateField) then
msgbox "date must be entered"
me.datefield.setfocus
cancel=true
End if
 
Back
Top