|
-
April 5th, 2007, 01:40 AM
#1
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
-
April 5th, 2007, 01:43 AM
#2
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.
If you find my answers helpful, dont forget to rate me 
-
April 5th, 2007, 04:29 AM
#3
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
Try, Try Hard, Try Harder one day you will Succeed.
-
April 5th, 2007, 04:53 AM
#4
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
Last edited by Bill Crawley; April 5th, 2007 at 04:59 AM.
If you find my answers helpful, dont forget to rate me 
-
April 6th, 2007, 03:46 PM
#5
Re: interaction between forms
Just wanted to thank you for the reply, useful.
Anna
-
April 6th, 2007, 04:40 PM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|