bobdowdy
asked on
How to dispose of a form in the load event?
I have a form that, in the load procedure, tries to find a file. If it finds it, fine, but if it can't locate the file, I want an error displayed, and the form to never appear.
In my FormLoad procedure, I have :
if filenotfound then
me.dispose
endif
this results in :
"cannot call dispose while doing createhandle"
Any ideas? Thanks
In my FormLoad procedure, I have :
if filenotfound then
me.dispose
endif
this results in :
"cannot call dispose while doing createhandle"
Any ideas? Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is not possible to just call close inside the FormLoad event either. You will see the same answer. CubixSoftware's approach is a good way to handle this. As an alternative to using a helper class you could just add a function to your form that returns whether or not your file exists. You could then call that before calling your .ShowDialog on it and just never show the form.
In your Form1 Class
Public Function FileExists() as boolean
Return True/False
End Sub
From your calling sub:
Dim frmName as new frmName
If frmName.FileExists() Then
frmName.showDialog()
Else
frmName.dispose()
End If
Hope that helps. I ran into this same problem about 2 months ago.
In your Form1 Class
Public Function FileExists() as boolean
Return True/False
End Sub
From your calling sub:
Dim frmName as new frmName
If frmName.FileExists() Then
frmName.showDialog()
Else
frmName.dispose()
End If
Hope that helps. I ran into this same problem about 2 months ago.
Calling Me.Close() from inside the MyBase.Load() event worked for me...
I wonder if it depends on how much is going on in the Form?? or in my situation my forms are MDI children. I wonder if that causes problems. I just tried the .close inside of my load and I received an error saying "Cannot call Close() while doing CreateHandle()".
It is interesting that it works in some applications and not others.
It is interesting that it works in some applications and not others.
...are we done here?
ASKER
Yup - were done - implemented CUBIX solution - all is fine - thanks to all we partiicpated !
In LOAD:
If FileNotFound Then
Me.Close()
Exit Sub
End If
In calling sub:
dim frmName As New frmName
frmName.ShowDialog()
frmName.Dispose()
Hope that helps...
Jake