Run 1 Command in Form2

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
thang74usAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RimvisCommented:
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"
    Form2.Show
End Sub

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


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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RuzReyCommented:
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
  Form2.Show
End Sub

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

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

Ruz
0
thang74usAuthor Commented:
Thank RuzRey
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.