calling function from form's code to module section (1 Viewer)

sree0009

Registered User.
Local time
Today, 04:16
Joined
Nov 20, 2017
Messages
15
hi i have a form which has code written in code module function(x)
now when i try to call this function(x) in my specific module it throws me sub or function not defined !! how can i correct this error? tried by changing it into public and removing private didn't work.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 06:16
Joined
Feb 28, 2001
Messages
27,001
Uncle G is right. Here is a more detailed explanation.

A form can "see" a function from two places - its own class module and a general module. (Exceptions exist but they are convoluted!) If you can't see it, you can't call it. It is called "scope" - and by the way, scope applies to functions, subs, and variables.

For your function:

Forms can have one module, called the class module. In the form's class module, ALL variables, subs, and functions are effectively private to the form. You can declare something to be public but it has no effect in that context. By habit, most of us will either not declare an explicit scope or will declare private scope.

If there is a sub-form associated with the form, it is actually a different form that has its own class module. Remember that you declare the sub-form separately and THEN associate it with the parent form through a sub-form control.

In a general module, things can be public, private, or declared with no explicit scope. By default, items are private to the general module, meaning that they can still be used by other elements from within the general module. However, if you declare items public from that general module, they become usable anywhere within the project.
 

Users who are viewing this thread

Top Bottom