[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

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
0
thang74us
Asked:
thang74us
1 Solution
 
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now