Monitoring Machine Running Time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to monitor machine running time. There are two ways I've thought
that this will be able to be carried out, but I'm not really sure how to do
it, or were to start. The time will have ti be monitored through a form, I
think. The form will be opened when the machine starts running.

1. When the form is opened a start time will be displayed, the current
time. When the machine stops running an end time button will be pressed,
this will then display the time the machine stopped running. The two times
would then be subtracted from each other to get the running time.

2. A stopwatch would be on the form. When the machine starts running you
press a button to start the timer. When the machine stops running you press
a button to stop the timer. This running time is then saved.

This running time is going to be used as part of a report, showing total
time available to machine, actual machine running time and machine downtime.

Thanks for the help

Tommy
 
yes, #1 is the way to go....

You don't need some "process" running. In fact you could even close the
form..and come back later, open the form, and hit the stop button.

in addition, you build a design in which several timers are going, because
they are only records with a start time logged, and the time is calculated
when you hit the stop button, and the "end time" is saved.....

So, this is very flexible, and you have not limit as to how many "timers"
running, since they are just start/end times in a table....
 
Depending on how granular you want the machine run time, I may not
necessarily agree with # 1. Depending on a lot of factors, the time for the
form to open and establish the start time will vary. This could create
incorrect data. The "stop watch" idea of pushing a button to start the
timing may be more accurate.

Also, if the OP is looking for sub second timing, the form timer event may
have to be called in on this one.

Here is code for an API call that runs a very accurate timer to the
millisecond.

Option Compare Database
Option Explicit

Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Private lngStartTime As Long

Public Sub StartTimer()
lngStartTime = timeGetTime()
End Sub

Public Function StopTimer() As Long
StopTimer = timeGetTime - lngStartTime
End Function
 
Well since we are relying on users to note the start and stop time by
pressing a button on the screen, I don't think we really need to worry about
accuracy too much.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
I agree, John; however, I think it would be good to make the OP aware of the
issues and options.

If the OP would like to convert the measurement to Furlongs per Fortnight, I
can provide that formula as well :)

("of course I'm mad, I've always been mad" - Pink Floyd/Dark Side of the Moon)
 
What does the code get attached to? Entered the code and attached it to the
start and stop buttons, StartTimer and StopTimer, but it came back with an
error message. Will this also display the timer on the form?

Thanks for the help

Tommy
 
I've got the timer working, its in an unbound form, however, I need to use
this time as part of a report that will show the actual time the machine was
running for against the total available time. How do I save the time and
where will it get saved too?

Thanks for the help

Tommy
 
You should have a table to store that information. Your form should use
either the table or a query based on the table as the record source of the
form. The table should have a date/time field for each time and those fields
should be bound to the controls that display them.
 
The code I've got the timer working with is from:

http://support.microsoft.com/kb/142871/en-us

When I try and link this code to a table I get an error message at the line:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

The table name is 'tblTime' and the field name is 'Running Time'

I'm not sure were too enter the code you gave me. In the form I entered the
code into, just copied it exactly, I've got a text box called 'ElapsedTime'
and a button called 'btnStart'. The form isn;t linked to any tables just
now. the text box would be used to show the timer and the button would be
used to start and stop the timer.
 
The code from the link you posted should work just fine if you follow the
instructions exactly. I just created the form and it is working fine. What
is the error you are getting?
 
I'm getting:

Run Time error '2113'
The value you entered isn't valid for this field

When I click on Debug the following line is highlighted:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

I've copied the code exatctly as it appears in the link. The timer works
fine if the form and text box are unbound. The error only appears when I
link the form to the table: tblTimer with field: Running Time.

Thanks for the help

Tommy
 
Not sure how you are positioning on the correct record, but if you have the
table field Running Time bould to the control ElapsedTime, I would make
ElapsedTime an unbound control and create an invisible control on the form,
name it txtRunningTime (No Spaces, there should be no spaces in names), and
bind it to the field [Running Time]

Then Add a line of code to the btnStartStop Click event. Immediately after
this line:

TotalElapsedMilliSec = TotalElapsedMilliSec + _
(GetTickCount() - StartTickCount)

Add this line:
Me.txtRunningTime = TotalElapsedMilliSec

Let's see if this cures the error.
 
The timer is working fine now. Not getting an error message anymore. The
txt box txtRunningTime is coming up as a date and the time is not being
recorded in the table.

Klatuu said:
Not sure how you are positioning on the correct record, but if you have the
table field Running Time bould to the control ElapsedTime, I would make
ElapsedTime an unbound control and create an invisible control on the form,
name it txtRunningTime (No Spaces, there should be no spaces in names), and
bind it to the field [Running Time]

Then Add a line of code to the btnStartStop Click event. Immediately after
this line:

TotalElapsedMilliSec = TotalElapsedMilliSec + _
(GetTickCount() - StartTickCount)

Add this line:
Me.txtRunningTime = TotalElapsedMilliSec

Let's see if this cures the error.
--
Dave Hargis, Microsoft Access MVP


Tommy2326 said:
I'm getting:

Run Time error '2113'
The value you entered isn't valid for this field

When I click on Debug the following line is highlighted:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

I've copied the code exatctly as it appears in the link. The timer works
fine if the form and text box are unbound. The error only appears when I
link the form to the table: tblTimer with field: Running Time.

Thanks for the help

Tommy
 
Is the txtRunningTime bound to the table field?
What is the table field's data type?
--
Dave Hargis, Microsoft Access MVP


Tommy2326 said:
The timer is working fine now. Not getting an error message anymore. The
txt box txtRunningTime is coming up as a date and the time is not being
recorded in the table.

Klatuu said:
Not sure how you are positioning on the correct record, but if you have the
table field Running Time bould to the control ElapsedTime, I would make
ElapsedTime an unbound control and create an invisible control on the form,
name it txtRunningTime (No Spaces, there should be no spaces in names), and
bind it to the field [Running Time]

Then Add a line of code to the btnStartStop Click event. Immediately after
this line:

TotalElapsedMilliSec = TotalElapsedMilliSec + _
(GetTickCount() - StartTickCount)

Add this line:
Me.txtRunningTime = TotalElapsedMilliSec

Let's see if this cures the error.
--
Dave Hargis, Microsoft Access MVP


Tommy2326 said:
I'm getting:

Run Time error '2113'
The value you entered isn't valid for this field

When I click on Debug the following line is highlighted:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

I've copied the code exatctly as it appears in the link. The timer works
fine if the form and text box are unbound. The error only appears when I
link the form to the table: tblTimer with field: Running Time.

Thanks for the help

Tommy

:

The code from the link you posted should work just fine if you follow the
instructions exactly. I just created the form and it is working fine. What
is the error you are getting?
--
Dave Hargis, Microsoft Access MVP


:

The code I've got the timer working with is from:

http://support.microsoft.com/kb/142871/en-us

When I try and link this code to a table I get an error message at the line:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

The table name is 'tblTime' and the field name is 'Running Time'

I'm not sure were too enter the code you gave me. In the form I entered the
code into, just copied it exactly, I've got a text box called 'ElapsedTime'
and a button called 'btnStart'. The form isn;t linked to any tables just
now. the text box would be used to show the timer and the button would be
used to start and stop the timer.





:

You should have a table to store that information. Your form should use
either the table or a query based on the table as the record source of the
form. The table should have a date/time field for each time and those fields
should be bound to the controls that display them.
--
Dave Hargis, Microsoft Access MVP


:

I've got the timer working, its in an unbound form, however, I need to use
this time as part of a report that will show the actual time the machine was
running for against the total available time. How do I save the time and
where will it get saved too?

Thanks for the help

Tommy
 
The txtRunningTime is bound to the table field. The data type in both the
field Running Time and txtRunningTime is Long Time. I've just changed the
txtRunningTime to a Long Time it only comes up with 00:00:00, not the time
displayed in the timer.

Klatuu said:
Is the txtRunningTime bound to the table field?
What is the table field's data type?
--
Dave Hargis, Microsoft Access MVP


Tommy2326 said:
The timer is working fine now. Not getting an error message anymore. The
txt box txtRunningTime is coming up as a date and the time is not being
recorded in the table.

Klatuu said:
Not sure how you are positioning on the correct record, but if you have the
table field Running Time bould to the control ElapsedTime, I would make
ElapsedTime an unbound control and create an invisible control on the form,
name it txtRunningTime (No Spaces, there should be no spaces in names), and
bind it to the field [Running Time]

Then Add a line of code to the btnStartStop Click event. Immediately after
this line:

TotalElapsedMilliSec = TotalElapsedMilliSec + _
(GetTickCount() - StartTickCount)

Add this line:
Me.txtRunningTime = TotalElapsedMilliSec

Let's see if this cures the error.
--
Dave Hargis, Microsoft Access MVP


:

I'm getting:

Run Time error '2113'
The value you entered isn't valid for this field

When I click on Debug the following line is highlighted:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

I've copied the code exatctly as it appears in the link. The timer works
fine if the form and text box are unbound. The error only appears when I
link the form to the table: tblTimer with field: Running Time.

Thanks for the help

Tommy

:

The code from the link you posted should work just fine if you follow the
instructions exactly. I just created the form and it is working fine. What
is the error you are getting?
--
Dave Hargis, Microsoft Access MVP


:

The code I've got the timer working with is from:

http://support.microsoft.com/kb/142871/en-us

When I try and link this code to a table I get an error message at the line:

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" & MilliSec

The table name is 'tblTime' and the field name is 'Running Time'

I'm not sure were too enter the code you gave me. In the form I entered the
code into, just copied it exactly, I've got a text box called 'ElapsedTime'
and a button called 'btnStart'. The form isn;t linked to any tables just
now. the text box would be used to show the timer and the button would be
used to start and stop the timer.





:

You should have a table to store that information. Your form should use
either the table or a query based on the table as the record source of the
form. The table should have a date/time field for each time and those fields
should be bound to the controls that display them.
--
Dave Hargis, Microsoft Access MVP


:

I've got the timer working, its in an unbound form, however, I need to use
this time as part of a report that will show the actual time the machine was
running for against the total available time. How do I save the time and
where will it get saved too?

Thanks for the help

Tommy
 
Back
Top