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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Function in a form apparently not public

Status
Not open for further replies.

jgoodman00

Programmer
Jan 23, 2001
1,510
I have written a public function in a form, which will become a subform at runtime. At runtim, the mainform calls the function written within the subform. As far as I remember learning, a public function is 'a function available to all other procedures in all modules'. Why when I try to compile these modules does it throw the error message stating that the sub or function is undefined???

James Goodman
j.goodman00@btinternet.com
 
From what I know when something is public in the module of a form its public only to that form. Create a module and paste your code in their. That way it will available no matter what
 
That is certainly the way it looks, but every document, including the help files state that a public variable/sub/function is 'available to all other procedures in all other modules' (Viescas 1999).

As standard practice, I always declare public variables/subs/functions in a module, but this one really requires use of the me keyword, so it needs to be placed within the specific module, because the form which fronts this module is a subform in a variety of instances. Therefore implicitly referencing this would be almost impossible, or at the least very messy. It is therefore beneficial to situate the function within the form & declare it as public so that any one of the mainforms can call the function when it is needed......

D'Oh!

James Goodman
j.goodman00@btinternet.com
 
My only other thought is how its being called? From what I get out of the documentation is that when you call a public method(sub or function) that is in the module of a form you have to call it as follows: Forms!frmName.methodname Other than that I don't see any other way
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top