Vb.net close form at form load

rflorencio used Ask the Experts™
I call a function when load form. The function must close form if returns false. But when close form an error occurs. I think that is why the form has not yet been loaded. It´s possible contour the problem.


Can not recall the value Close () to perform CreateHandle ().
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You need to use paint event.

Try something like this.
Dim bDntClose As True

    Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

bDntClose = Your Func

End Sub

 Private Sub frmTest_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            If Not bDntClose Then
            End If
        Catch ex As Exception
        End Try
    End Sub

Open in new window

Top Expert 2006

is this a child form you are wanting to close? if so then could you not just hide then unhide the form?

what if you try to close it using the visiblechanged event?


srikanthreddyn143 code works, but i would like to call function in only one form event (if possible sure). When load form need verify if two tables have records. If one of them have not, i want inform user and close the form.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Top Expert 2006

then why cant this be all done on the form_load event

if CheckTables = false then
    continue on as normal
end if

ensure normal code is wrapped between else and end if

your CheckTable method will do the checking of records then return true if record exists, false otherwise

Is this how you have setup your code? Is checking of tables are you doing it as a separate procedure or within a form

Is this how you get the error then?


rockiroads, my code is not in form. Is in a separate procedure. If i put your code in form_load event i get the same error:
Can not recall the value Close () to perform CreateHandle ()
Did you try using my code?


Yes, your code work´s but i was trying to use only one line of code in the form events.
I didnt get what one line of code meant?


Your code works well in fact and i plan use it, but i would like call code in one single page event, only that.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial