CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    3

    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

  2. #2
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    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

  3. #3
    Join Date
    Feb 2005
    Location
    Kolkata, India
    Posts
    430

    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.

  4. #4
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    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

  5. #5
    Join Date
    Apr 2007
    Posts
    3

    Re: interaction between forms

    Just wanted to thank you for the reply, useful.
    Anna

  6. #6
    Join Date
    Aug 2006
    Posts
    145

    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
  •  





Click Here to Expand Forum to Full Width

Featured