Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2011, 05:16 AM   #1
mdlueck
Sr. Application Developer
 
Join Date: Jun 2011
Posts: 2,625
Thanks: 114
Thanked 296 Times in 283 Posts
mdlueck will become famous soon enough mdlueck will become famous soon enough
Correct syntax to make Class Function Private yet callable by instances of Class

Greetings,

I would like to make a function within a class Private, yet retain ability to call the function via "Me.FuncName" within the class.

At first I thought to change Public to Private for this particular Function in the Class. Other Functions in the class could not call it via "Me.FuncName"

I dropped the Private declariaton and now other functions in the class may call "Me.FuncName", however elsewhere in the program that use instances of this class, I see the Private FuncName showing up, via the VBA AutoComplete assistance.

1) So, is there no need to declare Class Funcs as Public since they show up without?

2) And how to make a Func Private, callable by the class itself only?

mdlueck is offline   Reply With Quote
Old 11-07-2011, 07:00 AM   #2
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Correct syntax to make Class Function Private yet callable by instances of Class

Quote:
Originally Posted by mdlueck View Post
1) So, is there no need to declare Class Funcs as Public since they show up without?
Yes it makes no difference but it's always good to be explicit. Functions are Public as default whereas (I believe) variables are Private as default.

Quote:
Originally Posted by mdlueck View Post

2) And how to make a Func Private, callable by the class itself only?
Not possible I'm afraid. VBA doesn't support any other scope declaration keywords. VBA doesn't fully support OOP as well.
vbaInet is offline   Reply With Quote
The Following User Says Thank You to vbaInet For This Useful Post:
mdlueck (11-07-2011)
Old 11-07-2011, 07:04 AM   #3
mdlueck
Sr. Application Developer
 
Join Date: Jun 2011
Posts: 2,625
Thanks: 114
Thanked 296 Times in 283 Posts
mdlueck will become famous soon enough mdlueck will become famous soon enough
Re: Correct syntax to make Class Function Private yet callable by instances of Class

Quote:
Originally Posted by vbaInet View Post
Not possible I'm afraid. VBA doesn't support any other scope declaration keywords.
eeewww... That is unfortunate that Private is not supported. I guess I will really discourage direct calling in the comments. (shrug).

mdlueck is offline   Reply With Quote
Old 11-07-2011, 07:14 AM   #4
mdlueck
Sr. Application Developer
 
Join Date: Jun 2011
Posts: 2,625
Thanks: 114
Thanked 296 Times in 283 Posts
mdlueck will become famous soon enough mdlueck will become famous soon enough
Re: Correct syntax to make Class Function Private yet callable by instances of Class

In fact I went as far as placing the prefix "Priv_" in the front of the name of the function. That way it is a bit more obvious in the VBA editor which smart guesses what you might be typing.
mdlueck is offline   Reply With Quote
Old 11-07-2011, 07:32 AM   #5
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Correct syntax to make Class Function Private yet callable by instances of Class

All you do is simply declare it as Private and don't use the Me. syntax when you call it within the class. Just call it using the function name.

vbaInet is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB recordset dosn't work in function or class module?!? basstard80 Modules & VBA 0 09-04-2010 01:31 PM
Passing one Class Module variable into second class module mcdhappy80 Modules & VBA 1 09-12-2009 10:56 AM
vba class mikevds Forms 5 02-25-2009 10:53 AM
Using The Date Class kkocak Modules & VBA 6 02-08-2007 03:50 PM
[SOLVED] EVAL function and MS Office Access Class Objects (help!) piknik Modules & VBA 0 01-19-2006 09:55 AM




All times are GMT -8. The time now is 03:29 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World