timestamp

T

Terrence Carroll

I have a checkbox tied to a timestamp "Resolved Date" field. What I want is
for everytime the checkbox is checked to have the timestamp "Resolved Date"
field to update to the current date. If the user accidentally checks the
checkbox I would like for them to have the ability to deselect the checkbox
and have the current date removed from the "Resolved Date" field.

Thanks,

Terry Carroll
 
A

Al Campagna

Terrence,
What type of field is the checkbox bound to. A numeric value?
A True/False Boolean?
I'll assume Boolean, and a name of [Resolved].
I'll also assume that [ResolvedDate] is bound to a Date/Time field.

Use the AfterUpdate event of Resolved...

Private Sub Resolved_AfterUpdate()
If Resolved = True Then
ResolvedDate = Now() ' date & time
Else
ResolvedDate = Null
End If
End Sub

Note: Date() yields the current system Date
Now() yields the current system Date and the Time
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

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

Bob Barnes

How about...

Private Sub YourCkBox_AfterUpdate()
If YourCkBox = True then
DateField = Format(Now, "mm/dd/yy")
else
DateField = Null
End sub

HTH - Bob
 
D

Dirk Goldgar

KenSheridan via AccessMonster.com said:
Terry:

Use an unbound check box (blank ControlSource property) and don't include
any
Boolean (Yes/No) field for it in the underlying table, just the Resolved
Date
field of date/time data type. To have both fields in the table would
introduce redundancy and leave the table open to inconsistent data.

In the form's Current event procedure set the value of the check box on
the
basis of there being a value in the Resolved Date field:

Me.[chkResolved] = Not IsNull(Me.[Resolved Date])

In the check box's AfterUpdate event procedure update the value of the
Resolved Date field with code like Al's, e.g. to insert the current date
with
no time of day:

If Me.chkResolved Then
Me.[Resolved Date] = VBA.Date
Else
Me.[Resolved Date] = Null
End If

BTW if you do this in a continuous form put the unbound text box in the
form
header, not in the detail section. Otherwise its value would change in
every
row as you move between rows as you'd really just be seeing multiple
instances of the same check box.


How about binding the check box to the expression,

=([Resolved Date] Is Not Null)

so that always reflects the state of the current record, even on a
continuous form, without any code in the form's Current event? Then put a
transparent command button on top of the check box, and create an event
procedure for that button like this:

Private Sub cmdToggleResolvedState_Click()

With Me.[Resolved Date]
If IsNull(.Value) Then
.Value = Date
Else
.Value = Null
End If
End With

End Sub
 

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

Top