OnTimer Event Closes Form

L

LouMalnati

When the below code runs for some reason the form gets
closed. Please note there is no longer any code in the
Form_Load event


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
 
V

Van T. Dinh

1. The statement

dteFileTme = Format((Now), "h:mm:s am/pm")

is a bit strange. Format returns a Variant of String type. You then assign
it to a Variable of DateTime type. Thus, you actually convert from DateTime
to String and then back to DateTime. My guess is that you only want the
time component and you should use:

dteFileTme = TimeValue(Now())

2. However, the above shouldn't cause the Form to close. Nothing in your
posted code indicates so. Suggest you use the step-by-step (F8) execution
of the code and see whether the posted code does this or some other code /
error closing the Form.
 

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