Open a Form at a Specific Time

  • Thread starter User via AccessMonster.com
  • Start date
U

User via AccessMonster.com

I would like to open a form at a specific time of the day, everyday.

Please help?
 
N

NuBie via AccessMonster.com

Scheduled Tasks should do what you want.

Steps
1. Open Control Panel
2. Look for Scheduled Tasks and double click it.
3. Click Add Scheduled Task then follow the wizard

hope that helps
 
U

User via AccessMonster.com

I'm sorry for the mix up, I should've been more specific.

The operation I need takes place within an already opened access form.

The main form stays open and at a specific time of day another form opens
within the same database. I would like the operation to occur every day at
the specified time.

Thanks
 
N

NuBie via AccessMonster.com

use the Form.Timer Event

here's a sample code. tweak it to suit your needs

Private Sub Form_Load()
Form.TimerInterval = 1000 ' set time interval
End Sub

Private Sub Form_Timer()
Label1.Caption = Time
End Sub
 
D

Dirk Goldgar

User via AccessMonster.com said:
I would like to open a form at a specific time of the day, everyday.


This can only be done if the database itself is open at that time of day,
every day. If you need to, you can use the system's task scheduler to make
that happen. But from a later message in this thread, I think you are
assuming that the database will be open, and not only that, that a specific
form will also always be open. In that case, you can use the Timer event of
that form (your "main form") to open the new form.

You would set the form's TimerInterval to some suitable value; say, 60000,
which would make it fire every minute. The exact value will depend on how
precise your timing needs to be. You would have an event procedure for the
Timer event that would determine whether the current time is the time at
which you want to open the other form, *and also* whether it has already
been opened today. If it's time to open it -- or past time -- and the form
hasn't yet been opened, the code would proceed to open it.

The exact method for determining whether the form has been opened already
today depends on things you haven't yet told us. Will the database and the
main form remain open from day to day, without ever being closed? I
wouldn't want to count on that. Will the main form be opened more than once
a day? If it's opened once and only once a day, then you might just turn
off the Timer event by setting the TimerInterval to 0 once you've opened the
second form -- if you aren't using the Timer event for anything else. Or
you could record, in a database table, the date on which the second form was
last opened, and check that before opening the form again.
 
U

User via AccessMonster.com

Will the database and the main form remain open from day to day, without ever being closed?
No, but the database is often left open from day to day.
Will the main form be opened more than once a day?
Yes, the main form is opened many times throughout the day.
if you aren't using the Timer event for anything else
I’m using the Timer to display the current system time on the main form.
 
D

Dirk Goldgar

User via AccessMonster.com said:
No, but the database is often left open from day to day.

Yes, the main form is opened many times throughout the day.

I’m using the Timer to display the current system time on the main form.


Then you have no choice but to record in the database the last date on which
the second form was opened. Suppose you have a table, "Settings", and in
that table you have a date/time field named "FormLastOpened" (of course
these are example names). Your form might have code like the following in
its module:

'------ start of example code ------
Option Compare Database
Option Explicit

Dim mdtFormLastOpened As Date

Private Sub Form_Open(Cancel As Integer)

' Look up and save the date on which the
' secondary form was last opened.

mdtFormLastOpened = _
Nz(DLookup("FormLastOpened", "Settings"), 0)

End Sub

Private Sub Form_Timer()

' ... code to update the time display on this form ...

' See if we should open the second form.
If mdtFormLastOpened <> Date() Then
If Time() >= #12:00 PM# Then ' PUT DESIRED TIME IN THIS STATEMENT
mdtFormLastOpened = Date()
DoCmd.OpenForm "YourSecondForm"
DBEngine(0)(0).Execute _
"UPDATE Settings SET FormLastOpened = Date()", _
dbFailOnError
End If
End If

End Sub
'------ end of example code ------
 
N

NuBie via AccessMonster.com

Try this and see what happens

Private Sub Form_Load()
Form.TimerInterval = 60000 ' initially fire it every minute
End Sub

Private Sub Form_Timer()
hours = Format(Time, "h")
If hours = 9 Then 'reset time interval at 9:00am or whatever
Form.TimerInterval = 180000 'fire it every 3 hours instead of every
minute
End If

Select Case hours
Case 9, 12, 15 'open forms at 9 AM, 12 noon, 3 PM
'open form2 here
MsgBox hours
End Select

End Sub
 
U

User via AccessMonster.com

Then you have no choice but to record in the database the last date on which
the second form was opened.

It seems like we may have gone a little off the track.

If the main form is left open, the second form should only open when the
system time is equal to 6:00pm.

Any other ideas?
 
U

User via AccessMonster.com

It seems like we may have gone a little off the track.

If the main form is left open, the second form should only open when the
system time is equal to 6:00pm.

Any other ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top