Run 1 Command in Form2

Posted on 2004-11-02
Last Modified: 2010-04-17
I have 2 Form (name: Form1 and form2)

I want, When Click  Command19 of Form1 then load Form2 and wite msgbox "Comamnd19" and When Click Command20 of Form1 then load Form2 and wite msgbox "Comamnd20"

Help me!
Thank you
Question by:thang74us
    LVL 19

    Accepted Solution

    You need to declare public variable in Form2, like this:

    Public sCaller As String

    Then in the Form2 Form_Load event:

    Private Sub Form_Load()
       MsgBox sCaller
    End Sub

    In the Form1:

    Private Sub Command19_Click()
        Form2.sCaller = "Command19"
    End Sub

    Private Sub Command20_Click()
        Form2.sCaller = "Command20"
    End Sub

    BTW, I strongly recommend to give meaningful names to controls, like "cmdSave" instead of "Command19"

    Expert Comment

    Try adding a module to your project. In the Module:-

    Global sCommandToDo as string

    Then in form2:-

    Private Sub Form_Load()
      if sCommandToDo <> "" then
        MsgBox sCommandToDo
      end if
    End Sub

    In form1 you set sCommandToDo to the message you want, before loading form2:-

    Private Sub Command19_Click()
      sCommandToDo = "Command19"
      load Form2
    End Sub

    Private Sub Command20_Click()
      sCommandToDo = "Command20"
      load Form2
    End Sub

    A global can be seen by any form in your project.


    Author Comment

    Thank RuzRey

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A short article about a problem I had getting the GPS LocationListener working.
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now