Click to See Complete Forum and Search --> : Control form from another form
Gabriell
Feb 5th, 2003, 12:22 AM
How can we control another form from another form? I mean we control form A from from B. For example, if we click button OK on form A, the action will occur on form B.
Mr.No
Feb 5th, 2003, 02:24 AM
Gabriell
You can refer to controls in formB from formA as follows:
' cmdUpdate event is in form A
private sub cmdUpdate_Click()
frmFormB.txtCustid.Text = 123
End Sub
I personally don't like this technique of explicitly refering to a control on another form. You can alternatively add a public method in Form B and then invoke that method from form A
' Code in form B
Public sub UpdateCustomerID(byval custid as string)
txtCustid.Text = custid
End sub
' code in form A
' cmdUpdate event is in form A
private sub cmdUpdate_Click()
frmFormB.UpdateCustomerID("123")
End Sub
Athley
Feb 7th, 2003, 02:53 AM
Send a instance of the first form to the second form when its opened. To do that rewrite the constructor of the second form to take a form as an argument. Something like this...
Dim baseForm as Form1
Public Sub New(frm as Form)
baseform = frm
InitializeComponent()
End Sub
Then you have a reference to the form.
Pirate
Feb 7th, 2003, 06:01 AM
Originally posted by Gabriell
How can we control another form from another form? I mean we control form A from from B. For example, if we click button OK on form A, the action will occur on form B.
or you could declare instances of your forms in a module as follow:
'in a module
dim frm1 as new form1
dim frm2 as new form2
'in a form :
frm2.button1.name ="blah"
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.