Re: OnTimer event-Form does not load:Here is the code

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: LouMalnati (anonymous_at_discussions.microsoft.com)
Date: 08/19/04


Date: Thu, 19 Aug 2004 06:13:13 -0700

I will try this today. Regarding the variables they are
global variables which are declared in another module. I
assume this is ok ?

>-----Original Message-----
>Lou,
>
>Firstly, I think your code can be simplified somewhat, as
shown below. Try
>using this code before we look at anything else.
>
>Also chrErrorBody, chrRecips, chrCcRecips, and
chrbccRecips are not declared
>anywhere; you might want to do declare and populate them
before attempting
>to run this procedure.
>
>Private Sub Form_Timer()
> 'On Error GoTo frmstartup_err
>
> Dim ErrorNumber
> Dim strErrorMsg As String
> Dim strErrBuild As String
>
> strErrorMsg = "FormTimer Function Failed"
>
> Select Case FormatDateTime(Now, vbShortTime)
> Case #7:00:00 AM# To #4:30:00 PM#
> If WeekDay(Date)-1 < 5 Then
> LoadData
> End If
> End Select
>
>Exit_Here:
> 'Prevent the event from re-firing
> Me.TimerInterval = 0
> Exit Sub
>
>frmstartup_err: ' Error-handling routine.
> ErrorNumber = Err.Number
> strErrBuild = chrErrorBody & " " & ErrorNumber &
strErrorMsg
> SendNotesMail chrErrorSubject, "", chrRecips, _
> chrCcRecips, chrbccRecips, strErrBuild, True
> Resume Exit_Here
>End Sub
>
>Also, you're calling Form_Timer from within Form_Load.
There's no need to do
>that; if TimerInterval > 0, the Timer event will fire
without having to
>explicitly call it. Once the Timer event has completed,
set TimerInterval =
>0, to stop the event re-firing. I've done this in the
above code.
>
>Private Sub Form_Load()
> Me.TimerInterval = 1000
>End Sub
>
>Regards,
>Graham R Seach
>Microsoft Access MVP
>Sydney, Australia
>
>Microsoft Access 2003 VBA Programmer's Reference
>http://www.wiley.com/WileyCDA/WileyTitle/productCd-
0764559036.html
>
>
>"LouMalnati" <anonymous@discussions.microsoft.com> wrote
in message
>news:7aff01c48455$e6fca4a0$a601280a@phx.gbl...
>>
>> The form never displays
>>
>> >-----Original Message-----
>> >Lou,
>> >
>> >When you say "it never loads", do you mean:
>> > * the form displays but no controls are visible, or
>> > * the form never displays.
>> >
>> >Regards,
>> >Graham R Seach
>> >Microsoft Access MVP
>> >Sydney, Australia
>> >
>> >Microsoft Access 2003 VBA Programmer's Reference
>> >http://www.wiley.com/WileyCDA/WileyTitle/productCd-
>> 0764559036.html
>> >
>> >
>> >"Lou Malnati" <anonymous@discussions.microsoft.com>
wrote
>> in message
>> >news:687d01c4838e$0a2fdc80$a301280a@phx.gbl...
>> >> Please note the form WILL load if LoadData never gets
>> run
>> >> (eg. its a week-end). If LoadData gets called then
for
>> >> some reason the form never loads even though I see
the
>> >> OnLoad event ending (when I step-thru the code it
gets
>> to
>> >> End Sub but the form never loads.)
>> >> Option Compare Database
>> >> Option Explicit
>> >>
>> >> Private Sub Form_Load()
>> >> Call Form_Timer
>> >> End Sub
>> >>
>> >> Private Sub Form_Timer()
>> >> 'On Error GoTo frmstartup_err
>> >>
>> >> Dim dteFileTme As Date
>> >> Dim dt As Long
>> >> Dim ErrorNumber
>> >> Dim strErrorMsg As String
>> >> Dim strErrBuild As String
>> >>
>> >>
>> >> strErrorMsg = "FormTimer Function Failed"
>> >>
>> >> dteFileTme = Format((Now), "h:mm:s am/pm")
>> >> dt = WeekDay(Date)
>> >>
>> >> Select Case dteFileTme
>> >> Case #7:00:00 AM# To #4:30:00 PM#
>> >> Select Case dt
>> >> Case 2 To 6
>> >> Case Else
>> >> Exit Sub
>> >> End Select
>> >> Case Else
>> >> Exit Sub
>> >> End Select
>> >> LoadData
>> >>
>> >> Exit_Here:
>> >> On Error Resume Next
>> >>
>> >>
>> >> Exit Sub
>> >>
>> >> frmstartup_err: ' Error-handling routine.
>> >>
>> >> ErrorNumber = Err.Number
>> >> strErrBuild = chrErrorBody & " " & ErrorNumber &
>> >> strErrorMsg & ""
>> >> SendNotesMail chrErrorSubject, "", chrRecips,
>> >> chrCcRecips, chrbccRecips, strErrBuild, True
>> >> Resume Exit_Here
>> >>
>> >>
>> >>
>> >>
>> >> End Sub
>> >>
>> >>
>> >>
>> >>
>> >> >-----Original Message-----
>> >> >Hi,
>> >> >
>> >> >
>> >> >The Timer would fire only when it is created, so,
only
>> >> AFTER the form
>> >> >hosting it is loaded.
>> >> >
>> >> >==========================
>> >> >Option Compare Database
>> >> >Option Explicit
>> >> >
>> >> >Private Sub Form_Load()
>> >> > Debug.Print "Form_Load"
>> >> >End Sub
>> >> >
>> >> >Private Sub Form_Timer()
>> >> > Debug.Print "Form_Timer"
>> >> > Call Form_Load
>> >> >End Sub
>> >> >==========================
>> >> >
>> >> >with a timer interval of 1000 prints, in the
immediate
>> >> debug window, the
>> >> >messages, as expected. Your setting does not
>> seem "clear"
>> >> to me, if it is
>> >> >different, what is it, with code (just the relevant
>> >> parts)?
>> >> >
>> >> >
>> >> >
>> >> >Hoping it may help,
>> >> >Vanderghast, Access MVP
>> >> >
>> >> >
>> >> >
>> >> >"LouMalnati" <anonymous@discussions.microsoft.com>
>> wrote
>> >> in message
>> >> >news:64f601c48329$ce958620$a301280a@phx.gbl...
>> >> >> I call the OnTImer event when I load a form.
Within
>> the
>> >> >> OnTimer Function I call another function called
>> Import
>> >> ().
>> >> >> When the Import Function and OnTimer Function is
>> >> completed
>> >> >> and the code goes back to the original OnLoad
event
>> and
>> >> the
>> >> >> the OnLoad even ends the form never loads.
>> >> >>
>> >> >> I have stepped thru this sub several times and
>> confirmed
>> >> >> that it gets to "End Sub" within the OnLoad
event,
>> but
>> >> it
>> >> >> never loads the form.
>> >> >>
>> >> >> Any ideas ?
>> >> >
>> >> >
>> >> >.
>> >> >
>> >
>> >
>> >.
>> >
>
>
>.
>



Relevant Pages

  • Re: Working with SUBs
    ... Module-level variables are declared *before* the first Sub or Function in the module. ... A module level variable can be used by any routine within the same module. ... Global variables are also declared before the first Sub or Function of a module, ... If you declare a variable locally and pass it as a parameter to another routine, you know that there is only one point at which the two routines interact. ...
    (microsoft.public.word.vba.general)
  • Re: "my" variables and recursive regexp strangeness
    ... > I have something strange happening with a recursive regexp compiled ... > It works fine when the sub parts of it are global variables, ... to declare the variables in the same statement that uses them, ...
    (comp.lang.perl.misc)
  • Declare Variable
    ... Declare your global variables at the top of ... not inside the SetRefs proc. ... Private Sub Workbook_Open ...
    (microsoft.public.excel.programming)
  • Calendar Object
    ... it won't allow me to declare the global variables ... >>Still create the Calendar form. ... >>The calendar Form should have the following Sub ...
    (microsoft.public.access.reports)
  • sundial program
    ... It designs sundials. ... DECLARE SUB KeyPause ... PRINT "Should screens be saved to disk, ...
    (comp.lang.basic.misc)