Solved

run a code from another form

Posted on 2001-08-16
9
176 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
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
 
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
IT, Stop Being Called Into Every Meeting

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!

 
LVL 5

Accepted Solution

by:
rkot2000 earned 15 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

13 Experts available now in Live!

Get 1:1 Help Now