Unfortunately Access does not do time durations very well. (Nor does Excel
for that matter).
The date/time data type is really for storing absolute *points* in time,
rather than durations. That is why a duration longer than 24 hours starts
getting formatted as some date in the distant past - for example, 25h 30m
would be formatted as "31-Dec-1899 01:30".
I have come to the conclusion that the best way is to use a numeric field
and store a number of units (minutes or seconds, depending on your
granularity) and then use your own parsing and formatting code to convert to
and from text.
The formatting is easy:
Function MinsToHHMM( Mins As Variant ) as String
If IsNumeric(Mins) Then
MinsToHHMM = (Mins \ 60) & Format( Mins Mod 60, ":00" )
End If
End Function
(note that Mins is a Variant so it can handle a null value in a field)
Parsing depends on your requirements and how flexible you want to be with
data entry. For example, do you want to allow just a single number and, if
so, is it interpreted as hours or minutes; and do you want to allow decimal
points and, if so, should "2.5" be interpreted as 2:05 or 2:30.
Anyway, the technique is to have an unbound text box for data entry. In
your form's Current event, format the field value and store the result in
the textbox. In the textbox's BeforeUpdate event, parse the input and if
it's valid, store the result in the field, otherwise cancel the event.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
"x" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hi
> i am a pilot by profession. i want to create a database of my logbook
> using ms access 2002. i am facing a problem regarding the format of
> time field. when i select "Data/Time" data type for my time field then
> this format gives the liberty to record times uptill a figure of 59 in
> different sub-formats, whereas i want the format to be able to record
> the times like 80:35 or 1:10 or 1138:00. which means that i have these
> many hours on a specific aircraft. i also want to carryout sum
> operation on these timings. i have found out that i can use "[hh]:mm"
> format in ms excel 2002 to suite my requirements but it doesn't work in
> access.
> i am a very basic user of access or for that matter any database.
> please consider this while replying my question. i have no background
> of vb code which means that i will only be able to work the things out
> which are not very advanced (point and shoot mouse user).
> Thanx in advance and please be eleborate in your reply.
> bye and tc
>
|