Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Function from another Form 1

Status
Not open for further replies.

JaeBrett

Programmer
May 5, 2003
196
0
0
CN
How do you call a function from another form ... or can you?


Thanks.
 
basically, if its a private function then no if its public then yes!!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
Hello!

Sure you can! Let's say for example you have a function under Form1 named MyFunction(...).
Make sure it's Public Function ... and then just call it with
Form1.MyFunction(...)
or
Call Form1.MyFunction(...)

I hope this helps
Gregor
 
Declare it as Public in a form module and call it as :[tt]
x = Form1.myFunc()
[/tt]
(where Form1 is the name of the form containing the function and myFunc is the name of the function.

Or Declare it as Public in a Code (.bas) module and just use it by name;
[tt]x = myFunc()[/tt]


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
ok... so i forgot a little detail... but hey!! its late... [lol]

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
The Great Date Debate Thread222-368305
File Formats Galore @ or
 
By now I think you understand that the function must be public or called by a routine on the form that is public.

What gets tricky is setting a variable on one form from another. If you need to do that, you must set a reference to the specific instance of the targeted form on the form that will set the variable. Otherwise VB will give you a new instance of the targeted form that is not visable.


 
Perfect ... thanks for all the quick responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top