DataBase - Access 2007 + Time Formats - Sports Clocking

Asked By Sayth
14-Mar-10 10:03 PM
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.
SQL Server
(1)
Access 2007
(1)
VBA
(1)
Database
(1)
BeforeUpdate
(1)
CCur
(1)
AsandllowsourthfWith
(1)
AndFinancial
(1)
  John W. Vinson replied to Sayth
15-Mar-10 01:06 AM
An Access Date/Time value will not allow any precision finer than seconds, as
you have 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]
  flebber replied to John W. Vinson
15-Mar-10 02:07 AM
m>
o
tted
for
and
e a
hat
te
evel
is
, as
and
llows
ourth
f

With regard to your code
Where exactly do I insert code, in the VBA editor when creating the
form? Is that correct
  John W. Vinson replied to flebber
15-Mar-10 02:19 AM
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]
  david replied to John W. Vinson
15-Mar-10 04:07 AM
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)
  flebber replied to david
15-Mar-10 07:54 AM
ds,
s:3qfrp55q4st7ci6ashe4qscfogp3umo1s0@4ax.com...
to
s
te
.
ate
d
t
ds,
s
nd
of
o

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 =3D 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
  John W. Vinson replied to flebber
15-Mar-10 06:56 PM
I am suggesting storing the seconds and hundredths in one number - I do not 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 am 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 am 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 \ is not a typo - it is 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]
  a a r o n . k e m p f replied to Sayth
15-Mar-10 08:56 PM
I am not sure that Access datatypes have the level of precision that
you are looking for






ted
or
nd
a
at
e
vel
is
  flebber replied to a a r o n . k e m p f
16-Mar-10 08:10 AM
to
s
utted
for
and
te a
that
.
ate
d
level
t is

Maybe not, but Access has many other advantages. The fact that a
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.
  Sayth replied to John W. Vinson
17-Mar-10 08:06 AM
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.
  Sayth replied to flebber
18-Mar-10 07:13 PM
Found this article on SQL, most of the content seems relevant to Access as
well. Interesting that SQL has no data-type for durations as well.

This is a very good article and very much reinforces your method John.

http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-server
  Sayth replied to Sayth
18-Mar-10 07:16 PM
Re: Above I found two articles that reinforce what you have already advised
but they are very helpful as well, they are SQL artciles but seem quite
relevant to Access.

http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

http://www.sqlteam.com/article/working-with-time-spans-and-durations-in-sql-server
  david replied to Sayth
21-Mar-10 08:27 PM
But note that people DO work with months and years :~)  Rent and
Financial  Instruments are two areas that spring to mind, so some
people need to and do calculate duration in months and years.

(david)
help
DataBase Might be outgrowing Access but daunted by SQL Server I am close to completing the consolidation of various small Access databases and a couple of Excel spreadsheets that my little company uses (5 staff) into an all encompasing Access database and I was planning on splitting the database when I was finished to allow simaltaneous use of it by staff on our small
DataBase ADODB reference? I am working wtih Access 2007 and writing my VBA code that connects to my backed database wtih ADODB (ADOX). I have found lots of examples, many of them work, but I the same thing, so I am looking for the definitive reference when using ADODB in Access 2007 so I can learn about all of the methods, classes, etc. Thanks, Corta In Access 2007, open the code window, click the Help button on the toolbar, and go to
DataBase Invalid Reference Error I have two Access 2000, properly split, applications deployed at a client. Both are quite complex (58, 000 and while I also receive error 3020 (Update or CancelUpdate without AddNew or Edit), in the BeforeUpdate event of a bound (main or sub) form. I hve not been able to duplicate cause, and / or solution? We do have a project in the works to convert to SQL Server back end and Access 2007 front end, but it has been put on hold for a while. - - AG Email: npATadhdataDOTcom would like to explain the following An MDE file is the same as a regular Access MDB database file, with the following changes: 1 All VBA procedures are compiled ? converted from
DataBase Problem validating Field Value I am getting a message that "You cancelled the previous operation" each time the following sub is called. Access 2003 XP Pro (my workstation) I just finished creating a new Db and importing all file in case further actions make things worse. The only times I have seen the VBA editor behave in strange ways is when I had an open form with a Timer Paste to put the code back into the form's (new) module. - - Marsh MVP [MS Access] If I understand what you are saying, I suspect that you have a form open event. If so, the form event is grabbing the focus and that automatically trips the VBA verification process when you are entering VBA code. So look for an open (perhaps hidden) form with a timer event and a timer interval other than zero. John Spencer Access MVP 2002-2005 2007-2009 The Hilltop Institute University of Maryland Baltimore County Stefan and Marshall, Marshall, you were