insert date automatically when clicking a check box

S

Sylvie

Hello
I'm using Access 2007. How do you insert a date automatically when the user
selects a check box? On my form, there is a check box named Closed, if the
user checks the box, today's date should display automatically next to it.
How do you do that? In advance, thanks everyone for any help you can provide.
 
D

Danny J. Lesandrini

You'll need to put code in the AfterUpdate() event of the checkbox.
Something like this ...

If Me!chkClose = True Then
Me!txtCloseDate = Date()
Else
Me!txtCloseDate = Null
End If

This assumes if someone checked it as Closed and then unchecked it, the
edit would be undone. You might also add one of these calls to save the
changes immediately ...

Me.Dirty = True
or
DoCmd.RunCommand acCmdSaveRecord

The DoCmd call often throws an error for me, I don't know why, so I usually
just set Dirty to false. That has the same effect.
 
S

Sylvie

awesome. Thank you so much Danny. It works great.
One more question, for an option group with Yes or Not, how would you enter
the date automatically when either option is selected. Thanks
 
D

Danny J. Lesandrini

It's the same code without an IF condition. If the Frame Control's After Update
event, put this code ...

Me!txtCloseDate = Date()
 
Top