interaction between forms
If I want to call form1 by pressing a command button on form2, do the two forms have to exist in the same project? I have tried the following:
Private Sub CmdCalcu_Click()
Call frmCalculator.Form_Load
End Sub
to call the frmCalculator.frm from frmNumbers.frm, by pressing cmdCalcu.cmd,
but every time the application is launched, i receive the error message:
Tun time error - Object required.
Please give me a suggestion of what could be wrong. I'm pretty new in this area...
Thank you
Re: interaction between forms
both forms should reside in the same project and you should use:
frmName.Show to load the form.
If your starting out, you should use .NET version of VB and not VB6.
Re: interaction between forms
Sorry to drop in.
Is there any way by which we can call an event say click event of one from from other
regards
Amarjit
Re: interaction between forms
Yes you can.
You can do something like this
place a button on form1 and a button on form2.
form1 code might be:
Code:
Private Sub Command1_Click()
Form2.ButtonPressed = True
Form2.Show
End Sub
and form2 code might be:
Code:
Private blnButtonPressed As Boolean
Private Sub Command1_Click()
MsgBox "Hello"
End Sub
Public Property Let ButtonPressed(ByVal vNewValue As Boolean)
blnButtonPressed = vNewValue
End Property
Private Sub Form_Load()
If blnButtonPressed = True Then Command1_Click
End Sub
or form2 might have:
Code:
Private blnButtonPressed As Boolean
Private Sub Command1_Click()
MsgBox "Hello"
End Sub
Public Property Let ButtonPressed(ByVal vNewValue As Boolean)
blnButtonPressed = vNewValue
If blnButtonPressed = True Then
Command1_Click
End If
End Property
When you press the button on form1, you will get the messagebox appear before form2 shows, but this demonstrates the idea. Though you can remove form2.show if you follow the code in example2 for form2. You will still get the messagebox without the form2 showing
Re: interaction between forms
Just wanted to thank you for the reply, useful.
Anna
Re: interaction between forms
if you want to click a button you can just do:
Code:
' on Form1
Private Sub Command1_Click()
Form2.Command1.Value = True
End Sub
however, I would recommend doing something like:
Code:
' On Form1
Private Sub Command1_Click()
Form2.ClickButton
End Sub
' On Form2
Public Sub ClickButton()
Call DoSomething
End Sub
Private Sub Command1_Click()
Call DoSomething
End Sub
Private Sub DoSomething()
MsgBox "Clicked"
End Sub