Run form_timer from module

W

Wayne-I-M

Hi

I have a number (between 200 and 1,500) report that I e mail various clients
weekly from windows scheduler.

Open Access
Run AutoExec macro
Run Code (module) - open form - wait 10 seconds - do "stuff"

The whole thing works fine "if" the form is opened manually but fails on the
scheduler - the form "must" be fully opened before I run the code as the e
mail addess take a while to load - this is the reason for waiting 10 seconds
before starting the code.

But ??? I can not seem to run the forms timer from the module - if I put
XXXOnClick then it works fine - but of course this would run the code on_open
and so I use the forms timer to hold everything up for a while.

How do I reference the form's timer from a module ? something like this

Option Compare Database
Option Explicit

Public Function mailweeklyreports()
On Error GoTo mailcharityreports_Err
DoCmd.OpenForm "frmReportSelector", acNormal, "", "", , acNormal
Call Form_frmReportSelector.Form_Timer
Exit Function
mailweeklyreports_Err:
MsgBox Err.number & vbCrLf & Err.Description
Err.Clear
End Function

Note that I am trying to call the form's timer to run this

Private Sub Form_Open(Cancel As Integer)
Me.TimerInterval = 10000
End Sub

Then run this


Public Sub Form_Timer()
Dim varItem As Variant
Me.TimerInterval = 0
For Each varItem In Me.ComboReportSelector.ItemsSelected
etc
etc
etc

Any ideas would be helpful on running the forms timer from the module

Thank you
 
S

Stefan Hoffmann

hi,

Wayne-I-M said:
Open Access
Run AutoExec macro
Run Code (module) - open form - wait 10 seconds - do "stuff"

The whole thing works fine "if" the form is opened manually but fails on the
scheduler - the form "must" be fully opened before I run the code as the e
mail addess take a while to load - this is the reason for waiting 10 seconds
before starting the code.
Don't rely on the forms. Encapsulate the logic in a modul and call this
procedure.


mfG
--> stefan <--
 
P

pietlinden

Wayne,
just wondering, but what if you put a DoEvents in the code at the
beginning to force the other events to complete before your code
executes?

Pieter
 
S

Stefan Hoffmann

Wayne-I-M said:
what does Encapsulate mean in english
It is an idea from object oriented programming:
Create always seperate units which only have the members (variables) and
methods (subs, functions) they need to perform _one_ task or job.

So pack your logic code you use in your form into a seperate module.

This part of the so called Model-View-Controller pattern, which implies
that code reuse is easier when you generally seperate this three issus:

Model -> database related code
View -> form, report (presentation) related code
Controller -> logic


mfG
--> stefan <--
 

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