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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Does the Format() function provide the desired result?
Format(Time,"Medium Time")
Format("5:00","Medium Time")

Open in new window

Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

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

Me.f1.DefaultValue = Me.f1.Value
Jeffrey CoachmanMIS 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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.