Auto Date for check boxes

T

Tammy S.

I have check boxes and a date field for each box. When the box is checked,
I'd like to corresponding date field to automatically enter the current date.
How can I do this?
 
A

Al Campagna

Tammy,
What happens when the checkbox is unchecked (False)?
I'll assume you want the date field nulled out...

Use the AfterUpdate event of your checkbox (ex. chkExample) to
update the date field (ex. ExampleDate) (you use your own object names)

Private Sub chkExample_AfterUpdate()
If chkExample = True
ExampleDate = Date()
Else
ExampleDate = Null
End If
End Sub

Note: If you need the Date and Time in ExampleDate, use...
ExampleDate = Now()
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
D

dafe

Tammy S. said:
I have check boxes and a date field for each box. When the box is
checked,
I'd like to corresponding date field to automatically enter the current
date.
How can I do this?
 
T

Tammy S.

I'm getting an compile error: Expected: Then or GoTo. I have used the
underscore key between filed names that have more than one word. Could this
be causing the problem?

Example: EFIT_Confirmed is the check box and the corresponding date is
Date_Confirmed
 
A

Al Campagna

Tammy,
Re: using "_" instead of spaces in object names is just fine.
I think it's just my typo... mea culpa.
Try this... (notice the added Then)

Private Sub chkExample_AfterUpdate()
If chkExample = True Then
ExampleDate = Date()
Else
ExampleDate = Null
End If
End Sub
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
T

Tammy S.

Okay, got it in, shows up in all corresponding fields (check box and date
box), but the parenthesis after = Date keep disappearing.
 
J

John Spencer

Yeah, that happens. As long as it continues to work, don't worry about it.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
D

Duane Hookom

The () disappearance in a module is normal. Don't worry about it. This is one
of the reasons you should never name a field or control "Date".
 
T

Tammy S.

It doesn't work.

John Spencer said:
Yeah, that happens. As long as it continues to work, don't worry about it.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

.
 
A

Al Campagna

Tammy,
First, provide the names of these two controls so we don't have
to keep using "example" names.

"Doesn't work" doesn't tell us anything. No errors?

Please cut and paste "exactly" the code you placed in the checkbox
AfterUpdate event.

Where did you place that code? Have you used module vb code before?
What do you mean by "shows up...." There should be no code involved for
the date control, just the checkbox.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
T

Tammy S.

Okay, the checkbox is EFIT_Confirmed, the date field is Date_Confirmed.

I have entered the code as follows:

Private Sub chkEFIT_Confirmed_AfterUpdate()
If chkEFIT_Confirmed = True Then
Date_Confirmed = Date
Else
Date_Confirmed = Null
End If
End Sub

Note the () after date disappears as soon as I move to the next line of code.
 
A

Al Campagna

Tammy,
The () after Date is not a bug. Intellisense removes it from
module code, but in other places, the () is necessary. Don't worry
about that...

Next, you say the Name of the checkbox is
EFIT_Confirmed,
but your code is in the
chkEFIT_Confirmed
AfterUpdate event, and... in the code itself... you refer to
IF chkEFITCommand = True

That's probably your problem. If the checkbox is truly
EFIT_Confirmed, then the code should be in the EFIT_Confirmed
AfterUpdate event, and your code should refer to
EFIT_Confirmed = True.
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
T

Tammy S.

Aha! I was reading chk as part of the code, when it was part of the example
field name. Working fine now. Thank you very much for your help and
patience.
 

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

filtering data on report by date? 2
Last Visit information 7
Date search query 0
Please help 5
Auto Date / Time entry 5
Updating tables when you input new data 0
CheckBox Help 4
Conditional Sum in a Form 7

Top