Update a date/time control when check box control is updated

B

BrianP

I have two columns in tbl.Jobs. One field is a bit data type that I named
Jobs.OnHold and the control on the form is a check box. I also have a
date/time field named HoldDate. I want the hold date field to automatically
udpate with the current date everytime the check box control is udpated. What
is the best way to accomplish this?
 
M

maryb

I have a similar question. I have a field called "Sold" which is a check box.
When I check it I want the field "Date of Sale" to automatically fill in
with todays date. I understand going to the "after update event" but I don't
know what code to write.
Hope you can help. Thank you
 
K

Klatuu

When you say field, we need to qualify that. Forms don't have fields, they
have controls. Tables and queries have fields. So, to answer your question,
assuming Sold and Date Of Sale are actually controls on your form, it would
be:

Private Sub Sold_AfterUpdate()
If Me.Sold = True Then
Me.[Date Of Sale] = Date
End If
End Sub

If you posted field named instead of control names, use the names of the
controls the fields are bound to. Note the brackets [] around Date Of Sale.
That is necessary because you used spaces in a name. Names should not have
spaces or any other special characters. They should contain only letters,
numbers, and the underscore character. They should also not be Access
reserved names like Date, Time, Name, Description, Year, Month, Day, etc.

Being careful about your naming will save you a lot of headaches.
 
D

Doug Shatto

Dave,

I have the following code in a form of my database that is similar to that posted below but it is not updating the date control. Any help is appreciated.

Private Sub Returned_AfterUpdate()

If Me.Returned = True Then
Me.Return_date = Date
End If


End Sub
 
K

Klatuu

Is Returned a check box?
That is the only way it would work.
If it is a check box and it is not updating the control, then either you
have some corruption in the form or there is something else happening.
 

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