Variables Getting Reset After Displaying Form from another Form

Situation: I have a main form, a menu option displays a second form.  2nd form contains a listbox of items, selecting an item from the listbox allows a button to be pressed which displays a 3rd form.  Upon closing the 3rd form the focus is returned to the 2nd form.  

Everything works fine when you've selected 1 item from the listbox, but on the second item (no matter which item in the list that may be), by display/unloading the 3rd form variables held in the 2nd form are reset, i.e. a disconnected recordset I hold from having say 10 items suddenly has 0.

I initially thought it was maybe because I was displaying both forms 2 and 3 as modal, but I've tried it with modeless and the same thing happens.  I'm confused why values held in the 2nd form should be effected by another form, in addition not all variables are reset making it even more confusing, any help/suggestions would be great.

Running VB6 SP5 on Windows 2000 Pro


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you made the variables global?
Add a module to your project and declare the variables in the module using
Public Var1 As String
you should make a Property Get Set in  a Module

Private m_form2Vars as whatever

Public Property form2Vars() As Integer
            form2Vars = m_form2Vars
        End Get
        Set(ByVal Value As Integer)
            m_form2Vars  = Value
        End Set
   End Property

And you can set or get the value

form2Vars =  
JEGBIE2Author Commented:
Thanks, while I accept what you propose will work, what I still don't understand is why the private variables on the 2nd form get reset at all.  Form 2 is basically an object, by displaying a 3rd modal form you are not unloading the 2nd form or reinitialising it, it should therefore retain the same state+values it had before you displayed the 3rd form when you unload the 3rd form, if it didn't it would make displaying more than 1 form at a time useless.

Also the fact it does retain values the first time but then loses them the 2nd time makes me think there's something else causing the problem.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Is any reason you unload the form2 and restart?

The Form in .NET is a Class when you Load it it just makes an Instance not the actual Form. Soin essence the data is lost
I meant you may unload the form2 and restart in your code?

Show us some code

You can debug from debug menu, add watch with your variable name and

select break in value change on watch type
Just out of curiousity, are you performing init or load procedures/functions from your Form_Activate routine on your Form2 ?

If so, that would possibly explain why when closing form3 your vars get dumped or reset.  Obviously, the form_activate gets called when form3 is unloaded whether it is modal or not.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Are you just using to load the form or are you creating an object of Form2 and displaying that.
JEGBIE2Author Commented:
I think I was having one of those working too long and hard on a tight deadlined project and I needed someone to state the obvious!  The problem was there was code in the form activate event which did reset variables, however, I had these covered by a flag which is why I couldn't understand it, but it appears due to a mistake on my part this flag was reset at a point in error so after the first time the form activate code was run, DOH DOH DOH!  Thanks everybody who commented, I'm off to raid the fridge for a forbidden donut :)
LOL.  Glad it was something simple - thanks for grade.

See ya around more on EE!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.