Time Function

fabian24

New member
Local time
Today, 14:40
Joined
Dec 20, 2008
Messages
7
I have been working on this access form with the help of all the people online. I have almost acheived 95% of what I wanted.
The place that I am stuck right now is the Time. Is there a way the time pops up on the field.

I am attaching the program.

Your help is most welcome.

Thankyou.
 

Attachments

I'm not able to download your example, because of security policies here at work - but I'd love to help if you could just describe the problem in a little more detail...

Do you want a date/time field to be automatically populated when a record is created? Easiest way to do that is to set the default value to Now() in the table design.
 
I just want the time to be update on the field. I do not want the date.
The date can go in the date field.
 
One thing to note about Date/Time fields ... you will ALWAYS have a date component and a time component. You see date/times are stored as a number (a Number/Double) to be exact. The unit of measure for that value is "Days". The value is the number of days aways from a base date. The base date for VBA/Access is Dec 30 1899 12:00 AM. So when you store 12:00 PM, you are storing a value of 0.5 where the zero is the date component of 12/30/1899 and the .5 is the partial days passed midnight (.5 = 12 hrs, thus .5 = 12:00PM).

So ... when I hear (read) that you have TWO fields (one for Date and one for Time) I want to let you know that BOTH of those fields already have a Date and Time component and you should eliminate one of them and utilize a Date/Time field for both pieces of information you want available to your users, to do otherwise is an unwise strategy that often yeilds unexpected errors and behaviors when manipulating data.

If you wish to separate the date and time components on a form or report, you can use an Unbound text box control with a control source expression that separate out the portion you want ...

=DateValue([YourDateTimeFieldName])

=TimeValue([YourDateTimeFieldName])

With each unbound text box you use, you may want (or need) to adjust the Format property to display the value as you wish to show it ... this leads us into another method ... you could create two unbound text boxes that have a control source expression that looks like this ...

=[YourDateTimeField]

Then in the Format property of each control set it according to your preferences:

mm/dd/yyyy -- will show just the date portion of the fields value
hh:nn am/pm -- will show just the time portion of the fields value

...................

Hope this helps!
 
I am not sure what the problem is

Me.DatePrinted = Now() will give a combo of date time

The filed Expiry Time appears to gave a date entered. Enter a time as in 2.30pm and it won't bound around when you click in it.

By the way, impressive looking form
 
Just a point of note ... Time() still sets the field with a date component, its just that the date component is 12/30/1899 ...

... It is my contention that having two fields to indicate a date and a time is not a good design practice and will eventually lead to issues that will require band-aids to fix. One field is all that is needed.... so ... my recommendation is to drop Expiry Time and just utilize Expiry Date (be sure the change the Format property).

In addition, your table structure does not adhere to the "best practice" known as "normalization" ... are you interested in learning more about that? .... Your app will be a stronger app in the end if you learn the concept... :) ....
 
Last edited:
Just a point of note ... Time() still sets the field with a date component, its just that the date component is 12/30/1899 ...

... It is my contention that having two fields to indicate a date and a time is not a good design practice and will eventually lead to issues that will require band-aids to fix. One field is all that is needed.

If you only had one field how to you do an A to Z or Z to A on time?
 
In case votes are being tabulated, I'm with Brent. I have a couple of early applications where I stored date and time separately, and I regret it. It's more of a headache than storing them together in the long run. As Brent so ably pointed out, that's the nature of the data type anyway. It's easy enough to present them separately to the user if appropriate.
 
In case votes are being tabulated, I'm with Brent. I have a couple of early applications where I stored date and time separately, and I regret it. It's more of a headache than storing them together in the long run. As Brent so ably pointed out, that's the nature of the data type anyway. It's easy enough to present them separately to the user if appropriate.

How do you do it.

I could do that with Right/Left applied to a Now() but I assume you are not referring to that.

End the mystery:)
 
Brent already addressed one way:

If you wish to separate the date and time components on a form or report, you can use an Unbound text box control with a control source expression that separate out the portion you want ...

=DateValue([YourDateTimeFieldName])

=TimeValue([YourDateTimeFieldName])
 
But what is entered in the field.

How do I enter 2.30pm for 25/12/08 (or 12/25/08)

If a telemarketer gains an appointment for 10.30am on 15/1/08 I have it so he clicks on the date (a tabular display) and a combo opens and he clicks the time and obviously I have two fields.

Are we talking about making the two entries and then joining them?

I am sure as MVPs you blokes know what you are talking about but I am lost:confused:
 
DatePortion = Format(YourDateTimeField, "MM/DD/YYYY")

TimePortion = Format(YourDateTimeField,"HH:MM:SS")
 
Are we talking about making the two entries and then joining them?

Sure. Either of these should work:

Me.CombinedField = Me.txtReqDate & " " & Me.txtReqTime
Me.CombinedField = Me.txtReqDate + Me.txtReqTime
 
Sure. Either of these should work:

Me.CombinedField = Me.txtReqDate & " " & Me.txtReqTime
Me.CombinedField = Me.txtReqDate + Me.txtReqTime

OK, so two entries are made. I did not think there could be a way of doing it with one:D

I understand that you are saying date/time should be stored together and then split for viewing or whatever, but what is the problem that can occur.

Currently I will have the following fields as in fields in a table

Now() AppointmentDate AppointmentTime

That would be replaced by

Now() inserted into table field so no change

Date and Time......where are they being entered. Would they go into unbound textboxes and then a "join" is setvalued to a table field?
 
Yes, for data entry I'd use 2 unbound textboxes (or your combo box) and put them together in a hidden textbox bound to AppointmentDateTime (or the field name of your choice). You can use the after update event of the textboxes or the form itself.
 
In short we finish with what looks like a Now() entry.

I had no idea that storing a date and a time in different fields could lead to a problem.
 

Users who are viewing this thread

Back
Top Bottom