Time Calculations

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

Guest

Hi,

I want a form to close after a certain amount of time, but cannot work out
the calculation to do it.

When the form opens, the current time is stored in dteOpen.

How do I subtract dteOpen from Time() to get 2 minutes? All I get is some
spurious number with loads of decimal places!

My On_Timer event contains an if statement:

If dteOpen - Time > 2 then
Docmd.close acform,"FrmPrint"
end if

I have tried allsorts, but to no avail.

Any takers?

Cheers,
Steve.
 
In your form's properties:
Set Timer Interval to 12000 (=2 minutes)

In the On Timer event

Docmd.close acform,"FrmPrint"

That is all you need.
 
Ok, that works, but, how would I show a count of how long is left until the
form closes?

This is for part of an automated reports run where a form opens giving the
user the option to print a variety of reports. I want the reports to print
and the form to close after a period of inactivity so the rest of the
automated will complete itself....

I hope this makes sense,

Cheers,
Steve.
 
Going back to the basics, What is the underlying NEED that you have to
close the form? Is keeping the form open causing problems for other
users? Is it a security issue where the reports that can be printed
contain information of a confidential nature?
 
Right, reports need to be ran on a daily basis which can take up to 3 hours.
These reports are ran on a 'standalone' PC. The user clicks the GO button
and then leaves the DB to do its stuff.

Towards the end of the process, a form opens to give the user the option to
print reports. 1 of the reports needs to be printed no matter what.

All I want is a Label on the form to say "Report Production will Continue
in: " & Time Remaining

When the time reaches 0 (after 2 minutes), the selected report(s) are
printed automatically and the form closes. At this point execution is passed
back to the function used to produce the reports.

I can do everything else, all I need to know is how to calculate the
difference between a stored time and the current time, it cant be that hard
can it?

Steve.
 
1. I would add into the code as the very last line or otherwise where
appropriate the DoCmd.OpenReport statement to force the required report
to print.

2. There's no need to ask the user to print the reports after the
reports are run. All you have to do is give the user a message box using
the MsgBox() function. Capture the response (YES or NO) into a variable
and then once the reports are completed, use the value in a If...Then
statement to print the optional reports.

David H
 
Just for the record, I have eventually worked it out.

In the Form_Open event, I used the TimeSerial function to Add 2 minutes to
the current time:

dteForm_Open = TimeSerial(Left(Time, 2), Mid(Time, 4, 2) + 2, Right(Time, 2))

Then in the Form_Timer event, I subtracted dteForm_Open from the Time and
waited for the results to get to 0, then Called the Print button OnClick
event and Closed the form.

dteTime_Open = Time - dteForm_Open

lblCount_Down.Caption = "Default Button will be selected in : " &
dteTime_Open
Me.Repaint

If dteTime_Open = 0 Then

lblCount_Down.Caption = "Button Selected."
btnPrint_Click
DoCmd.Close acForm, "frmPrint_Reports"

End If

I knew it would be a simple answer.

Steve.
 
Did you see my suggestion about prompting the user as to wether or not
to print the reports when the user submits the reports?
 
Back
Top