default time in datetime field (Access)

Dear experts - ok, a rather trivial question.
1) I want to set the default time on a datetime field, e.g., 5PM (but NOT set the date). I want to do this in default value for the field on the form.
2) We also create records on the fly (in VBA code) - when the record is created this way, how do I also set the default time (depending on the record type we might default it to 9 am or 5 pm, for example).
Who is Participating?
Jeffrey CoachmanConnect With a Mentor MIS LiasonCommented:
1. In the table, set the default value property of the field to: #5:00:00 PM#
You can do this is the form, but if you do it in the table, it stays with that table (if it is ever moved or copied)
...up to you

2.<depending on the record type we might default it to 9 am or 5 > 
Note that a default value is the default for *new records*
So this value will appear *as soon as you click the new record button* (even before you select a "Type"),...
So here you really just want to set a value based on the "Type"
(so this is technically not a default value.)

So just use code similar to this on the after Update event of the "Type" control:
If Me.Type = 1 Then
    Me.YourTime = #9:00:00 AM#
ElseIf Me.Type = 2 Then
    Me.YourTime = #5:00:00 PM#
End If

1) Select the "Default" property in the property sheet of the desired control, set it to =Time()
2) Set the value of the datetime field to Time().

i.e. you could use either date() or now(), depending on what you want.
terpsichoreAuthor Commented:
but i want to set specific times - what is the syntax for that? (not current time)
and in vba, i want to leave date alone as i create records, but again programmatically set times.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Does the Format() function provide the desired result?
Format(Time,"Medium Time")
Format("5:00","Medium Time")

Open in new window

If field is f1 has a value, then setting f1 default value as:

Me.f1.DefaultValue = Me.f1.Value
terpsichoreAuthor Commented:
thanks, very clear and comprehensive
terpsichoreAuthor Commented:
In the end this is what I used:
me.datefield = me.datefield + #17:00#  -- otherwise, it overwrote the date the user entered.
Jeffrey CoachmanMIS LiasonCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.