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.
paulinebelfordAsked:
Who is Participating?
 
GunsenConnect With a Mentor Commented:
This is said earlier, but....to access input fields from other forms, simply address it using global notation:  form.control.property :

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
0
 
VbmasterCommented:
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
0
 
mark2150Commented:
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!"
....
END SUB

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!"
....
END SUB

Within the calling form:

CALL MySub( Me.Text1 )



M
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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?
0
 
tomlacheckiCommented:
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

formname.object

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.

T
0
 
JimmieTooCommented:
Pauline:

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.

Jim
0
 
tomlacheckiCommented:
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
0
All Courses

From novice to tech pro — start learning today.