?
Solved

run a code from another form

Posted on 2001-08-16
9
Medium Priority
?
196 Views
Last Modified: 2012-06-22
Hi,

how can i run a code from another form , ex:

on click form1.command1 let it run form2.command1
but not by typing the same code of form2.command1_click in form1.command1_click

thanks
asamir
0
Comment
Question by:asamir00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Expert Comment

by:krees
ID: 6393911
Well, I think for that you create a global sub in a module of your project.
0
 
LVL 1

Expert Comment

by:Sorklin
ID: 6393920
You have to make sure that you have loaded the form 2 as an object in form one.  

For example, If form 1 loads form 2, create a module level global form2 object and when you load form2, set this global equal to the form2 object.

Then later in the code (when form1.command1 has been activated), you can call globalvariable.command1_Event (like _click) and it will activate.

If the forms are created independently from each other (by another main form, lets say), then there should be a global scope object assigned to form2.  When you originally create form2, the global would be assigned to it. ie.

dim frm as Form2

set frm = new Form2 (this will create a new instance of the form2 object)

frm.show

etc...
Then any form can access Form2 and its children by using the global frm.



0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6393937
The simplest way to do this is to go into form2 and change the

Private Sub Command1_Click()

to

Public Sub Command1_Click()

and then from form1 just do

Form2.Command1_Click

This will work as long as you only have one instance of Form2, ie you loaded it by doing Form2.show or load Form2. If Form2 has not been loaded in this manner, it will be loaded when you call the Command1_Click method. If you want to have multiple instances of Form2, so you are doing

Set frm = new Form2

then you need to take Sorklin's approach.

Zaphod.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:chaos_59
ID: 6393956
You can access the subs or functions of another form or module by making the sub type Public. Normally the subs of click events and such are created as private subs. If you change it to public you can access it from other forms and modules.

0
 
LVL 5

Accepted Solution

by:
rkot2000 earned 60 total points
ID: 6394163
chaos is correct, but with commandbutton
you can use value property to "click on command

form2.command1.value = true - will fire command1_click event.
0
 

Expert Comment

by:DevParty
ID: 6394763
0
 

Expert Comment

by:costello
ID: 6395011
DevParty

you are relatively new to this site so I would ask you to please read the guidelines on comments vs answers at the bottom of this page and on http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp 

It is not considered good practice to lock questions in this way, as this places these questions in the locked section and reduces the visibility of the question to other experts. It also tends to put pressure on the questioner to accept the proposed answer. In future, please do not post "answers" except in trivial questions which have one and only one answer such as what is 1+1. I know that is a bit simplistic but I am sure you get the idea.

Having said that I hope that you continue to contribute to this site and that your experience proves useful to many others in future.
I am also rejecting your answer, for above reasons.

By the way, as you can see, something went wrong with your comment anyway, it just shows 'No Text'

costello
Community Support Moderator @ Experts-Exchange
0
 

Expert Comment

by:ashraf_t
ID: 6395055
It is very easy just put the othe form name like form2 as :
form2.command1_Click
0
 

Expert Comment

by:costello
ID: 6395081
ashraf_t;

Please reread the comment I just made to DevParty.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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