Handling Erros In The Form_Load Routine

Handling Erros In The Form_Load Routine

In VB3, the PostMessage API can cancel an error during Form_Load. Theform unloads if you send a WM_CLOSE message to the loaded window in theerror handler of the Form_Load routine. It is not easy to find out fromthe calling routine exactly why the form unloaded. In VB4, you can create a property on your form to indicate success orfailure, and unload the form from the calling procedure depending uponthe value of that property:

 Public SuccessfulLoad As Boolean ' creates the property Form1.SuccessfulLoadPrivate Sub Form_Load()	SuccessfulLoad = True	If An Error Occurs Then	SuccessfulLoad = False	End IfEnd Sub

In the calling procedure:

 Sub LoadTheFubarForm()	Dim MyForm As Form1	Set MyForm = New Form1	Load MyForm	If MyForm.SuccessfulLoad Then		MyForm.Show vbModal	End If	Unload MyForm	Set MyForm = NothingEnd Sub


Share the Post: