dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Button click

  1. #1
    Join Date
    Mar 2006
    Posts
    228

    [RESOLVED] Button click

    hello,

    I know this is something simple..

    firstly I have two forms (form1, form2)

    I have a button on form2 (command1) and I want to run the code from that button from from1.

    I have tryed the following code:

    form2.command1_click

    but it don't seem to work.. anyone know how to do it?

    (I basicly want to press the button from another form.)

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,267

    Re: Button click

    Why not just include the code ( you want executed ) in a Public Sub, then just call the public sub from both places

    Or, just simply set the Private Sub Command1_Click() to Public, once you did that, this event will appear in form 1

    Form1
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Form2.Command1_Click
    End Sub
    Form2
    Code:
    Option Explicit
    
    Public Sub Command1_Click()
    MsgBox "hello"
    End Sub
    Last edited by HanneSThEGreaT; July 26th, 2007 at 01:53 AM.
    [SIGPIC][/SIGPIC]
    All my Articles
    Hannes

  3. #3
    Join Date
    Mar 2006
    Posts
    228

    Re: Button click

    hello,

    thanks for the quick reply..

    I got it working.. I ended up putting the public at the start of the command code and it worked!

    ---
    Option Explicit

    Public Sub Command1_Click()
    MsgBox "hello"
    End Sub
    ---

    and it works just fine..

    Thanks so much.

  4. #4
    Join Date
    Sep 2006
    Posts
    635

    Re: Button click

    another way to call method from any other Form is :

    Code:
    'in Form 1
    'in form2, Public sub Command1_Click
    CallByName Form2, "Command1_Click", VbMethod

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)