A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Access 2007 + Time Formats - Sports Clocking



 
 
Thread Tools Display Modes
  #1  
Old March 15th, 2010, 02:03 AM posted to microsoft.public.access
Sayth
external usenet poster
 
Posts: 7
Default Access 2007 + Time Formats - Sports Clocking

I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually inputted
or imported.

There will also be basic calculations performed on times e.g car a time for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times and
then be able to calculate differences in time and store them.

There seems to be two basic ways to go 1) create an input mask and create a
text field as mm:ss:uu, only I am unsure how to validate the inputs so that
seconds greater than 60 cannot be created or hundredths greater than 99.
Seems may have calculations complications to.

Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill level
but makes more sense, would like more information on this approach if it is
better?

Any ideas? Other ideas besides my two above appreciated.


  #2  
Old March 15th, 2010, 05:06 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Access 2007 + Time Formats - Sports Clocking

On Sun, 14 Mar 2010 19:03:02 -0700, Sayth
wrote:

I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually inputted
or imported.

There will also be basic calculations performed on times e.g car a time for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times and
then be able to calculate differences in time and store them.

There seems to be two basic ways to go 1) create an input mask and create a
text field as mm:ss:uu, only I am unsure how to validate the inputs so that
seconds greater than 60 cannot be created or hundredths greater than 99.
Seems may have calculations complications to.

Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill level
but makes more sense, would like more information on this approach if it is
better?

Any ideas? Other ideas besides my two above appreciated.


An Access Date/Time value will not allow any precision finer than seconds, as
you've evidently gathered. I would suggest storing the number as seconds and
fractions of seconds, in (odd as it may sound) a Currency field - which allows
four decimal places and has no roundoff error. You can have three unbound
textboxes on a Form, for hours, minutes, and seconds (e.g. 43.92) and a fourth
bound to this currency field. You can put code in the AfterUpdate event of
each of the time portion textboxes like:

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub

You can also put validation in the BeforeUpdate event of each textbox to
ensure that the value is appropriate.
--

John W. Vinson [MVP]
  #3  
Old March 15th, 2010, 06:07 AM posted to microsoft.public.access
flebber
external usenet poster
 
Posts: 9
Default Access 2007 + Time Formats - Sports Clocking

On Mar 15, 4:06*pm, John W. Vinson
wrote:
On Sun, 14 Mar 2010 19:03:02 -0700, Sayth
wrote:



I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually inputted
or imported.


There will also be basic calculations performed on times e.g car a time for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times and
then be able to calculate differences in time and store them.


There seems to be two basic ways to go 1) create an input mask and create a
text field as mm:ss:uu, only I am unsure how to validate the inputs so that
seconds greater than 60 cannot be created or hundredths greater than 99.
Seems may have calculations complications to.


Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill level
but makes more sense, would like more information on this approach if it is
better?


Any ideas? Other ideas besides my two above appreciated.


An Access Date/Time value will not allow any precision finer than seconds, as
you've evidently gathered. I would suggest storing the number as seconds and
fractions of seconds, in (odd as it may sound) a Currency field - which allows
four decimal places and has no roundoff error. You can have three unbound
textboxes on a Form, for hours, minutes, and seconds (e.g. 43.92) and a fourth
bound to this currency field. You can put code in the AfterUpdate event of
each of the time portion textboxes like:

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 *_
* * *+ NZ(Me!txtSeconds)
End Sub

You can also put validation in the BeforeUpdate event of each textbox to
ensure that the value is appropriate.
--

* * * * * * *John W. Vinson [MVP]


With regard to your code
Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub

Where exactly do I insert code, in the VBA editor when creating the
form? Is that correct
  #4  
Old March 15th, 2010, 06:19 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Access 2007 + Time Formats - Sports Clocking

On Sun, 14 Mar 2010 23:07:32 -0700 (PDT), flebber
wrote:

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub

Where exactly do I insert code, in the VBA editor when creating the
form? Is that correct


Create the Form; select each of the three hours/minutes/seconds textboxes in
turn and view their Properties. On the "Events" tab select the After Update
line and click the ... icon by it; choose "Code Builder" and insert this code
(using your own actual control names of course).
--

John W. Vinson [MVP]
  #5  
Old March 15th, 2010, 08:07 AM posted to microsoft.public.access
david
external usenet poster
 
Posts: 398
Default Access 2007 + Time Formats - Sports Clocking

An Access Date/Time value will not allow any precision finer than seconds,
as


That is to say, Access has no way to enter or display a precision finer
than seconds, so you will have to build your own.

You can use an Access Date/Time value to store the data if you wish,
down to a precision of better than 1E-300, as Access does if you
connect to a SQL Server DateTime value.

But there may be no advantage to doing so, because of the lack of
input/output formats.

(david)

"John W. Vinson" wrote in message
...
On Sun, 14 Mar 2010 19:03:02 -0700, Sayth

wrote:

I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually
inputted
or imported.

There will also be basic calculations performed on times e.g car a time
for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times
and
then be able to calculate differences in time and store them.

There seems to be two basic ways to go 1) create an input mask and create
a
text field as mm:ss:uu, only I am unsure how to validate the inputs so
that
seconds greater than 60 cannot be created or hundredths greater than 99.
Seems may have calculations complications to.

Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill
level
but makes more sense, would like more information on this approach if it
is
better?

Any ideas? Other ideas besides my two above appreciated.


An Access Date/Time value will not allow any precision finer than seconds,
as
you've evidently gathered. I would suggest storing the number as seconds
and
fractions of seconds, in (odd as it may sound) a Currency field - which
allows
four decimal places and has no roundoff error. You can have three unbound
textboxes on a Form, for hours, minutes, and seconds (e.g. 43.92) and a
fourth
bound to this currency field. You can put code in the AfterUpdate event of
each of the time portion textboxes like:

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub

You can also put validation in the BeforeUpdate event of each textbox to
ensure that the value is appropriate.
--

John W. Vinson [MVP]



  #6  
Old March 15th, 2010, 11:54 AM posted to microsoft.public.access
flebber
external usenet poster
 
Posts: 9
Default Access 2007 + Time Formats - Sports Clocking

On Mar 15, 7:07*pm, "david" wrote:
An Access Date/Time value will not allow any precision finer than seconds,
as


That is to say, Access has no way to enter or display a precision finer
than seconds, so you will have to build your own.

You can use an Access Date/Time value to store the data if you wish,
down to a precision of *better than 1E-300, as Access does if you
connect to a SQL Server DateTime value.

But there may be no advantage to doing so, *because of the lack of
input/output formats.

(david)

"John W. Vinson" wrote in messagenews:3qfrp55q4st7ci6ashe4qscfogp3umo1s0@4ax .com...

On Sun, 14 Mar 2010 19:03:02 -0700, Sayth

wrote:


I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually
inputted
or imported.


There will also be basic calculations performed on times e.g car a time
for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times
and
then be able to calculate differences in time and store them.


There seems to be two basic ways to go 1) create an input mask and create
a
text field as mm:ss:uu, only I am unsure how to validate the inputs so
that
seconds greater than 60 cannot be created or hundredths greater than 99..
Seems may have calculations complications to.


Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill
level
but makes more sense, would like more information on this approach if it
is
better?


Any ideas? Other ideas besides my two above appreciated.


An Access Date/Time value will not allow any precision finer than seconds,
as
you've evidently gathered. I would suggest storing the number as seconds
and
fractions of seconds, in (odd as it may sound) a Currency field - which
allows
four decimal places and has no roundoff error. You can have three unbound
textboxes on a Form, for hours, minutes, and seconds (e.g. 43.92) and a
fourth
bound to this currency field. You can put code in the AfterUpdate event of
each of the time portion textboxes like:


Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 *_
* * + NZ(Me!txtSeconds)
End Sub


You can also put validation in the BeforeUpdate event of each textbox to
ensure that the value is appropriate.
--


* * * * * * John W. Vinson [MVP]


Thank you am trying to follow but I am not yet as advanced as you. So
the private sub names and fields change with each sub section

so seconds is

Private Sub txtSeconds_AfterUpdate()
Me!txtRacetime = NZ(Me!txMinutes)*60 + NZ(Me!txtSaeconds) * 60 _
+ NZ(Me!txtSeconds)
End Sub

That leaves me then with the input from I believe 2 unbound form boxes
for me being "minutes" and "seconds" and hundredths of seconds
recorded in a currency field.

Am I then amalgamating the fields to one field or how will I perform
calculations between time?

([txtMinutes]+[txtSeconds]+[hundredths]) + or - a similar combined
number?
  #7  
Old March 15th, 2010, 10:56 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Access 2007 + Time Formats - Sports Clocking

On Mon, 15 Mar 2010 04:54:35 -0700 (PDT), flebber
wrote:

Thank you am trying to follow but I am not yet as advanced as you. So
the private sub names and fields change with each sub section

so seconds is

Private Sub txtSeconds_AfterUpdate()
Me!txtRacetime = NZ(Me!txMinutes)*60 + NZ(Me!txtSaeconds) * 60 _
+ NZ(Me!txtSeconds)
End Sub

That leaves me then with the input from I believe 2 unbound form boxes
for me being "minutes" and "seconds" and hundredths of seconds
recorded in a currency field.

Am I then amalgamating the fields to one field or how will I perform
calculations between time?

([txtMinutes]+[txtSeconds]+[hundredths]) + or - a similar combined
number?


I'm suggesting storing the seconds and hundredths in one number - I don't see
any benefit to entering 13 (seconds) in one textbox and 41 (hundredths) in a
different textbox, vs. typing 13.41 into a single textbox.

The expression I posted:

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub

generates the combined number. The NZ (Null To Zero) function prevents errors
when a textbox is empty: anything plus NULL gives NULL, and the NZ function
converts the null value into a zero. There are 3600 seconds in an hour, and 60
in a minute, so I'm multiplying the entered number of hours by 3600 and the
entered number of minutes by 60, and adding those two products to the number
of seconds in the third textbox.

What I'm suggesting is that you have this identical expression in the
AfterUpdate event of the three textboxes, which I named txtHours, txtMinutes,
and txtSeconds. If you change any one of them, it will recalculate the sum of
the three and store the result into the textbox named txtRacetime, which would
be bound to the (currency, or decimal, or Double) race time field in your
table. It might be better to explicitly convert the calculated result to your
desired datatype: e.g. if the race time is a Currency field, use

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = CCur(NZ(Me!txtHours)*3600) _
+ CCur(NZ(Me!txtMinutes) * 60) _
+ CCur(NZ(Me!txtSeconds))
End Sub

You would also want to do the reverse - display the hours, minutes, and
seconds when you navigate to a record which already has a time. To do so put
code in the form's Current event:

Private Sub Form_Current()
If Not IsNull(Me!txtRacetime) Then
Me!txtHours = Me!txtRacetime \ 3600
Me!txtMinutes = Me!txtRaceTime \ 60 MOD 60
Me!txtSeconds = Me!txtRaceTime - 60 * (Me!txtRacetime \ 60)
End If
End Sub

The \ isn't a typo - it's the integer divide operator, so a a racetime of
128.24 seconds, integer divided by 60, is 2 minutes. The last expression gets
the remaining 8.24 seconds.
--

John W. Vinson [MVP]
  #8  
Old March 16th, 2010, 12:56 AM posted to microsoft.public.access
a a r o n . k e m p f @ g m a i l . c o m
external usenet poster
 
Posts: 1,108
Default Access 2007 + Time Formats - Sports Clocking

I'm not sure that Access datatypes have the level of precision that
you're looking for






On Mar 14, 7:03*pm, Sayth wrote:
I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually inputted
or imported.

There will also be basic calculations performed on times e.g car a time for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times and
then be able to calculate differences in time and store them.

There seems to be two basic ways to go 1) create an input mask and create a
text field as mm:ss:uu, only I am unsure how to validate the inputs so that
seconds greater than 60 cannot be created or hundredths greater than 99.
Seems may have calculations complications to.

Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill level
but makes more sense, would like more information on this approach if it is
better?

Any ideas? Other ideas besides my two above appreciated.


  #9  
Old March 16th, 2010, 12:10 PM posted to microsoft.public.access
flebber
external usenet poster
 
Posts: 9
Default Access 2007 + Time Formats - Sports Clocking

On Mar 16, 11:56*am, "a a r o n . k e m p f @ g m a i l . c o m"
wrote:
I'm not sure that Access datatypes have the level of precision that
you're looking for

On Mar 14, 7:03*pm, Sayth wrote:

I have a database I am starting to create. I need some guidance in how to
best create a time format for a "sports watch". What I need to record is
minutes:seconds:hundredths, however the times will need be manually inputted
or imported.


There will also be basic calculations performed on times e.g car a time for
lap 1 is 1:22:30 and this is 00:01:27 outside best time. So store times and
then be able to calculate differences in time and store them.


There seems to be two basic ways to go 1) create an input mask and create a
text field as mm:ss:uu, only I am unsure how to validate the inputs so that
seconds greater than 60 cannot be created or hundredths greater than 99..
Seems may have calculations complications to.


Create a table/template/format so that each time is inputted into separate
fields, so that minutes has its own field seconds etc. Then have a field
where it adds previous fields so ([mm]+[ss]+[uu]). Bit beyond my skill level
but makes more sense, would like more information on this approach if it is
better?


Any ideas? Other ideas besides my two above appreciated.


Maybe not, but Access has many other advantages. The fact that a
"duration" data-type doesn't exist is strange to me as a newbie since
a wide range of sports use them, cooking and recipes rely on duration
though maybe not as exacting, and there are plenty of business uses,
call centres (handle times/durations) etc. But testing the solutions I
am learning and should be able to overcome the time/duration
limitation.
  #10  
Old March 17th, 2010, 12:06 PM posted to microsoft.public.access
Sayth
external usenet poster
 
Posts: 7
Default Access 2007 + Time Formats - Sports Clocking



"John W. Vinson" wrote:

On Mon, 15 Mar 2010 04:54:35 -0700 (PDT), flebber
wrote:

Thank you am trying to follow but I am not yet as advanced as you. So
the private sub names and fields change with each sub section

so seconds is

Private Sub txtSeconds_AfterUpdate()
Me!txtRacetime = NZ(Me!txMinutes)*60 + NZ(Me!txtSaeconds) * 60 _
+ NZ(Me!txtSeconds)
End Sub

That leaves me then with the input from I believe 2 unbound form boxes
for me being "minutes" and "seconds" and hundredths of seconds
recorded in a currency field.

Am I then amalgamating the fields to one field or how will I perform
calculations between time?

([txtMinutes]+[txtSeconds]+[hundredths]) + or - a similar combined
number?


I'm suggesting storing the seconds and hundredths in one number - I don't see
any benefit to entering 13 (seconds) in one textbox and 41 (hundredths) in a
different textbox, vs. typing 13.41 into a single textbox.

The expression I posted:

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub

generates the combined number. The NZ (Null To Zero) function prevents errors
when a textbox is empty: anything plus NULL gives NULL, and the NZ function
converts the null value into a zero. There are 3600 seconds in an hour, and 60
in a minute, so I'm multiplying the entered number of hours by 3600 and the
entered number of minutes by 60, and adding those two products to the number
of seconds in the third textbox.

What I'm suggesting is that you have this identical expression in the
AfterUpdate event of the three textboxes, which I named txtHours, txtMinutes,
and txtSeconds. If you change any one of them, it will recalculate the sum of
the three and store the result into the textbox named txtRacetime, which would
be bound to the (currency, or decimal, or Double) race time field in your
table. It might be better to explicitly convert the calculated result to your
desired datatype: e.g. if the race time is a Currency field, use

Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = CCur(NZ(Me!txtHours)*3600) _
+ CCur(NZ(Me!txtMinutes) * 60) _
+ CCur(NZ(Me!txtSeconds))
End Sub

You would also want to do the reverse - display the hours, minutes, and
seconds when you navigate to a record which already has a time. To do so put
code in the form's Current event:

Private Sub Form_Current()
If Not IsNull(Me!txtRacetime) Then
Me!txtHours = Me!txtRacetime \ 3600
Me!txtMinutes = Me!txtRaceTime \ 60 MOD 60
Me!txtSeconds = Me!txtRaceTime - 60 * (Me!txtRacetime \ 60)
End If
End Sub

The \ isn't a typo - it's the integer divide operator, so a a racetime of
128.24 seconds, integer divided by 60, is 2 minutes. The last expression gets
the remaining 8.24 seconds.
--

John W. Vinson [MVP]
.


The penny finally dropped as to how exactly this was working. Got it.
Awesome thanks Heaps John for your help.

Your time and effort very much appreciated.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.