Error when using ME.Dispose closing a form

When I close a form and use Me.Close followed by Me.Dispose  It should return to another form, instead I get this error:

Unhandled exception has occurred in your application.  If you click continue the application will ignore this error and attempt to continue.  If you click quit the application will close immediately.

Collection was modified; enumeration operation may not execute.

It also mentioned something about:

Microsoft.VisualBasic.PowerPacks.ShapeCollecetion.Dispose

I use those for rectangles I have on the form.
NOTBOB90Asked:
Who is Participating?
 
NOTBOB90Connect With a Mentor Author Commented:
This did not correct the error.  I ended up removing all of the rectangle objects manually and that seems to have fixed the error.  I am not sure why just dispoing the form does not do the same, but whatever.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Get rid of the "Me.Dispose()" call...
0
 
NOTBOB90Author Commented:
I need it because it the form gets re opened, the old data is still there.  I want to to open the form with the default values of the form.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sounds like you're displaying the default instance of the form, such as:

    Form2.Show()

Instead, create a NEW instance each time:

    Dim F2 As New Form2
    F2.Show()

Now it will always be a new instance with the default values.

If this doesn't quite fit your scenario then please show your code that opens the form.
0
 
NOTBOB90Author Commented:
I took out the me.dispose, and I still get this error after closing the form.  See attached.

I think it may have something to do with rectangle buttons I put on the form not unloading.
New-Wordpad-Document.doc
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hmmm...

Can you show how you declared and displayed the form?

Under what conditions and how are you closing the form?
0
 
NOTBOB90Author Commented:
frmMemberLookup.Show()

opens the form that is basically an onscreen keyboard so a person can lookup a name in a database.  Once the name is located and clicked on, the user clicks select user which returns the information back to the main screen.  The form is also closed in that select user button:

Me.close
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Ok...it seems that my comment back here applies:
http://www.experts-exchange.com/Microsoft/Development/Q_27869534.html#a38413956

Is "frmMemberLookup" the name of the form?...or the name of a variable that is an instance of the form?

Most likely you need to change:

    frmMemberLookup.Show()

To:

    Dim lookup As New frmMemberLookup
    lookup.Show()
0
 
NOTBOB90Author Commented:
Because the solutons provided did not work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.