| VBCE cannot use
a Sub Main procedure for the startup object for the application, therefore the startup
object must be a form. If, during the start-up of your application (Form_Load) you decide
that the application needs to terminate, you must cannot use the
App.End method in the Form_Load event or an application error will result (See Q183420
& Q180520).
To prevent the error and end the application during start up, you must terminate in the
Form_Activate Event (you should tell the user with a message box). We do this by setting a
"flag" for us to check at a later time, during the form Activate event.
Option Explicit
Dim bAppShouldEnd 'Flag for
ending app on startup
Private Sub Form_Load()
On Error Resume Next
'Simulate an error and set flag
Err.Raise 7 'Out of
Memory
If Err.Number <> 0 Then
'An error occurred during form load,
'so exit the app by setting our flag.
MsgBox "Cannot start, error: "
& _
Err.Number
& " " & Err.Description
bAppShouldEnd = True
End If
End Sub
Private Sub Form_Activate()
If bAppShouldEnd Then App.End
End Sub |
 |
 |
 |
When the bugs get tough,
the tough get coding! |
|