Turn checkbox on and off

R

Richard John

I have a form with a checkbox field (chkActive) related to the value in the date
resigned field. It only half works. The check box is turned on as expected, when
the date resigned field is blank. the converse does not happen i.e. insert a
resigned date and the checkbox should be turned off.

Can someone please help me with this. Function code shown below:

Private Sub DateResigned_AfterUpdate()
If Len(Nz(Me!DateResigned, "")) = 0 Then
Me!chkActive = vbTrue 'WORKS
Else
Me!chkActive = vbFalse 'DOES NOT WORK
End If
End Sub


Thanks
 
K

Ken Sheridan

Try this:

Private Sub DateResigned_AfterUpdate()

Me.chkActive = IsNull(Me.DateResigned)

End Sub

However, if the check box is unbound you can pull the value into it without
any code by setting its ControlSource to:

=IsNull([DateResigned])

If it’s a bound control then use the event procedure to push the value in.
A bound control should only be used if you need to be able to override the
value pushed in by the code, though. If the control will always reflect the
absence or presence of a value in DateResigned then an unbound control should
be used and its value pulled in with an expression as its ControlCource
property. There is then no need for a corresponding Boolean (Yes/No) column
in the underlying table, as to have one introduces redundancy.

BTW I'd recommend munging your email address if you post it here, e.g.

rjbpond<at>bigpond<dot>net<dot>au

Otherwise you might well find it gets harvested by spammers.

Ken Sheridan
Stafford, England
 

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

Similar Threads


Top