paulinebelford
asked on
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.
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
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
ASKER
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?
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
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
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
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)=
Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
Well done Gunsen, I wasn't sure anyway and it's answered some of my problems too
Call nameoftheform.subname