Solved

Close a windows form from its own "MyBase.Load" Event

Posted on 2004-08-13
4
591 Views
Last Modified: 2008-03-17
Hi,

I'm trying to create a program that will open, perform a task and then close automatically. Here's the program...

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

        With Me.AxWebBrowser1
            .Navigate("http://sample.website.com/")

            Do
                Application.DoEvents()
            Loop While AxWebBrowser1.Busy

            '--Load username and password and submit the form
            .Document.myForm._email.value = "user@email.com"
            .Document.myForm._pass.value = "pass"
            .Document.myForm.submit()
            Do
                Application.DoEvents()
            Loop While AxWebBrowser1.Busy

       End With

       Me.Close

End Sub
'***************************

When the program tries closing the form at the end it results in a error: Cannot access a disposed object named "Form2"

Does anyone know how to achieve what I want to do without getting this error.

Thanks a lot for any help!
0
Comment
Question by:siono4
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Matti
ID: 11791673
Hi!

Try
Unload me

Matti
0
 

Author Comment

by:siono4
ID: 11791825
Hello Matti,

Nice idea but unfortunately doesn't work because when I use "Me" it refers to the windows form and I get the error:
Value of type 'Form2' cannot be converted to 'System.AppDomain'.

Maybe it's possible to unload the application domain but I don't know how to do this...
0
 
LVL 4

Accepted Solution

by:
hamood earned 125 total points
ID: 11791936
at the end of form1_onload use the key word end like this

Private Sub Form_Load()
    MsgBox "test"
   
    End
End Sub

hamood
0
 

Author Comment

by:siono4
ID: 11791989
Thats it, thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question