How to call a function that is in a module.

cafe_jay

Registered User.
Local time
Today, 05:16
Joined
Apr 2, 2012
Messages
17
I tried searching from this with no luck. I am a novice so this might be easy to others.

I have a module called myModule.

Inside this module I have a function called myFunction
Private Function myFunction() As Long

myFunction = 100

End Function

I would like to be able to call this function from any form...

for example:

Private Sub Form_Load()

Dim myNumber As Long

myNumber = myFunction

End Sub
 
Does it compile.

How do you know it is not working?

Do you get an error.
 
Yes, I get :
runtime error.
Object required.

Im guessing that means that my function isnt defined, the procedure doesnt know to look n the module? im not sure the syntax i am supposed to use
 
The Function you wrote cannot be Called from a Form as it is Private.

If you make it Public it will work.

So simply change

Private Function myFunction() As Long


to

Public Function myFunction() As Long
 
I had tried that and it did not work... but my function had a type that i had declared as..

Private Type myDimension
height as long
weight as long
End Type

Public Function myFunction As myDimension
qwertyuiop
End Function

So i made the type a public type and then i was able to use the function from anywhere.
Thank you!

Problem solved!
 

Users who are viewing this thread

Back
Top Bottom