Form Close during Form Load

CIMStu

Member
Joined
Mar 9, 2010
Messages
13
Programming Experience
Beginner
Hi All,

New to programming just writing my first application.

Basically during the form load event i carry out some checks to make sure i have database connection and a valid login, if these items fail i catch the exception and display a messagebox and change a boolean variable to false.

It then goes back to form load where i have an if statement which is if boolean variable = false then me.close

Trouble is this runs through to the conclusion of the form_load sub and then attempts to load and throws an instance of an object type exception.

I kinda understand the logic that i am trying to close the form before it has loaded, so put the close command in the form_activated routine, however this still eventually sends me back to the form load sub and tries to load the form, and then throws the same exception.

Can someone advise where i am going wrong? and how to rectify.

Thanks

Stuart
 
What you should do is use the application Startup event to make these checks and cancel the startup when needed. My.Application.Startup Event
 
I'll go ahead and show the form, in the Shown event I'll throw up the dialog(s) and if any of them fail (IE they don't have the rights to it) then I close the whole program. I also don't show any data on the form until after they've passed the login/DB check process.
 
Back
Top