Is all functions 'public' by default?

prabha_friend

Prabhakaran Karuppaih
Local time
Tomorrow, 02:54
Joined
Mar 22, 2009
Messages
1,032
I am just writing 'Function somefunctionname()' in a module. Please note that I am not using that ‘Public’ keyword here. But I am able to access that functions in every module. That means by default all functions are declared public? Want to confirm. Thank you.
 
Yes you are correct they are all public by default if they are stored in a standard module. If you want to make them private then you must declare them explicitly.

If you wrtie a function in a form module though it will be priate to that form even if you do not declare it.

David
 
May I suggest that you go to your VBA editor, type in "Function Statement" in help search bar and read the accompanying help file?

I think you will learn much more and find many answer if you get in habit of using the help files.
 
If you omit the "Public" keyword then they are global only to that module or form. If you use the Insert menu, Sub and choose Function, Access puts in the "Public" keyword for you. I believe a public function declaration looks like this:

Public Function blah(s as string) as integer
end function


If you type the function in by hand without using Insert, Sub and you omit the "Public" keyword then it is private to that module/form.
 
bulrush, I would suggest you read the help files because if you did, you may find you were mistaken.
 
dim myvar as sometype
private myfunc() as sometype

are visible only to the module in which they are declared

public myvar as sometype
public myfunc() as sometype or just
myfunc() as sometype

are visible to the entire app
 
Thanks, Gemma. I always use Insert, Sub so it always comes out with the Public keyword for me.
 

Users who are viewing this thread

Back
Top Bottom