OnTimer event-Form does not load

  • Thread starter Thread starter LouMalnati
  • Start date Start date
L

LouMalnati

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 ?
 
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
 
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
 
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
 
I will try this today. Regarding the variables they are
global variables which are declared in another module. I
assume this is ok ?
 
Back
Top