Working with multiple forms

I am trying to create a program with 3 separate forms: a menu, a form displaying contact details,which are stored in arrays,  and a 3r form for entering new contacts details into the array. But I need to access code from the separate forms and am unable to do this.
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.

Procedures and functions in forms are by default Private but you can change it to Public (just add the keyword Public in front of the Sub/Function/Property keyword in declaration - or of course replace if there is already a Private keyword thee). Then you can access a sub from anywhere in your project using code like..

  Call nameoftheform.subname
Either that or add a module and place all your PUBLIC routines in there. Structurally this is more correct.

You can pass a form name to the routines so the same routine can be used to on controls on different forms.

PUBLIC SUB MySub(Frm as Form)
frm.caption = "Hello!"

Within the calling form:

CALL MySub( Me )

You can also use Objects to pass a pointer to a control:

PUBLIC SUB MySub(Obj as Object)
obj.text = "Hello!"

Within the calling form:

CALL MySub( Me.Text1 )

paulinebelfordAuthor Commented:
My main problem is not calling the functions. The problem is that I need to use data, which is input into the forms at runtime, in my functions and the functions require data from both of the forms. Is this possible?
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

How are you calling the data? I'm not quite sure what you mean, but if I'm right, you should be using:

public sub example()

' the contacts form is called frm1
'     one of the fields here is fld11
'     another is fld12
' the menu is frm2
'     one of the fields here is 21
'     another is fld22'

' the 3r form is frm3
'     one of the fields here is 31
'     another is fld32'

' depending on what you are doing it
' should be something like:

frm1.frm11 = frm2.fld22

end sub

What I'm trying to demonstrate is the


method. This is the first thing I learned, so I'm sure you know - but it's just in case - after all, it could be your problem.


Here's one way to make your data available, there are a dozen more.  You could use a public UDT but let's use an array instead since you're already using arrays.  Put an array in a module, say Public sNewContactDetails(13) As String.  In the new contact details form, your textboxes should be an array, in which case, the textbox change event should have this  code: sNewContactDetails(Index)=txtDetails(Index).  Now that value is available everywhere in your app.  When you close the details form, clear it, or whatever, Erase the sNewContactDetails array.

This is said earlier, access input fields from other forms, simply address it using global notation: :

Form3.Text1.Text = Form1.Text1.Text
Form3.Text2.Text = Form2.Text1.Text

U do not have to add ".Text" since it's the default property.  If the conext is form3 then u can simply write :

Text1 = Form1.Text1
Text2 = Form2.Text1

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
o well, I suppose I'd better go straight for the answer when I think I've got it!

Well done Gunsen, I wasn't sure anyway and it's answered some of my problems too
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.