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:


I use those for rectangles I have on the form.
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.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Get rid of the "Me.Dispose()" call...
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.
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:


Instead, create a NEW instance each time:

    Dim F2 As New Form2

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.
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.
Mike TomlinsonMiddle School Assistant TeacherCommented:

Can you show how you declared and displayed the form?

Under what conditions and how are you closing the form?
NOTBOB90Author Commented:

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:

Mike TomlinsonMiddle School Assistant TeacherCommented: seems that my comment back here applies:

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:



    Dim lookup As New frmMemberLookup
NOTBOB90Author Commented:
Because the solutons provided did not work
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.