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

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-12-2019, 06:06 AM   #1
GBalcom
Much to learn!
 
Join Date: Jun 2012
Location: Georgia
Posts: 428
Thanks: 20
Thanked 4 Times in 4 Posts
GBalcom is on a distinguished road
setting the value (let) of a private class property

Hello,
Having a hard time within a new class module I created. It has a property called "CompanyName".

I've set the Get property to public (to expose it outside the class), and the Let property to private (I want to populate this value within the class with another method).

Here's the property:

Code:
Public Property Get CompanyName() As String
    ' Comments:
    ' Returns : String
    ' Created : 09/12/19 09:41 GB
    ' Modified:
    
    On Error GoTo PROC_ERR

    CompanyName = m_strCompanyName


PROC_EXIT:
    Exit Property

PROC_ERR:
    Err.Raise Err.Number
    Resume


End Property

Private Property Let CompanyName(NewValue As String)
    ' Comments:
    ' Params  : NewValue
    ' Created : 09/12/19 09:41 GB
    ' Modified:
    

    On Error GoTo PROC_ERR


    m_strCompanyName = NewValue

PROC_EXIT:
    Exit Property

PROC_ERR:
    Err.Raise Err.Number
    Resume


End Property

and here's the code to populate the value:
(recordset code omitted)

Code:
 Me.CompanyName = .Fields("NAME")

It won't compile. VBE highlights the me.companyname and says "Method or Data member not found". Even though it gave me the intellesense when writing it.

Any ideas?

GBalcom is offline   Reply With Quote
Old 09-12-2019, 06:14 AM   #2
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,782
Thanks: 34
Thanked 536 Times in 509 Posts
MajP will become famous soon enough MajP will become famous soon enough
Re: setting the value (let) of a private class property

You did not do anything incorrect. That is a dumb shortcoming of VBA. I think you can make a private function.
MajP is online now   Reply With Quote
Old 09-12-2019, 06:16 AM   #3
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,359
Thanks: 67
Thanked 2,683 Times in 2,569 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: setting the value (let) of a private class property

you should make it as Public.
and you don't assign a value inside the class.
you instantiate a class and assign value to it:

dim myClass as New clsCompany
myClass.Company = .Fields("Name")

__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-12-2019, 06:20 AM   #4
GBalcom
Much to learn!
 
Join Date: Jun 2012
Location: Georgia
Posts: 428
Thanks: 20
Thanked 4 Times in 4 Posts
GBalcom is on a distinguished road
Re: setting the value (let) of a private class property

I think I found a work around. basically, I'll loose the Let properties, and just keep the module level variable. Then I'll just populate that.

Arnelgp,
because in VBA, we cannot instantiate a class and pass arguments, I make a method I call "init", where I pass over anything necessary and populate everything in 1 shot.

In this case, all I'm passing into my init method is the primary key for that table, and my init method will populate all the properties.
GBalcom is offline   Reply With Quote
Old 09-12-2019, 06:22 AM   #5
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,782
Thanks: 34
Thanked 536 Times in 509 Posts
MajP will become famous soon enough MajP will become famous soon enough
Re: setting the value (let) of a private class property

https://www.access-programmers.co.uk...ivate+property
MajP is online now   Reply With Quote
Old 09-12-2019, 06:26 AM   #6
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,359
Thanks: 67
Thanked 2,683 Times in 2,569 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: setting the value (let) of a private class property

yes, you can do it in Public sub/func init().
then from init() you can call your Let Company property.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-12-2019, 07:08 AM   #7
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,782
Thanks: 34
Thanked 536 Times in 509 Posts
MajP will become famous soon enough MajP will become famous soon enough
Re: setting the value (let) of a private class property

Quote:
I think I found a work around. basically, I'll loose the Let properties, and just keep the module level variable. Then I'll just populate that
Read the thread I posted. If you want you can keep the private property, but must call it without the Me keyword.

MajP is online now   Reply With Quote
Old 09-12-2019, 11:48 AM   #8
GBalcom
Much to learn!
 
Join Date: Jun 2012
Location: Georgia
Posts: 428
Thanks: 20
Thanked 4 Times in 4 Posts
GBalcom is on a distinguished road
Re: setting the value (let) of a private class property

I read it, but I don't understand how to call it, without the keyword me. what is ObjAppSettings?
GBalcom is offline   Reply With Quote
Old 09-12-2019, 12:14 PM   #9
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,782
Thanks: 34
Thanked 536 Times in 509 Posts
MajP will become famous soon enough MajP will become famous soon enough
Re: setting the value (let) of a private class property

call without Me should work.
CompanyName = .Fields("NAME")
instead of
me.CompanyName = .Fields("NAME")
MajP is online now   Reply With Quote
Old 09-13-2019, 01:22 AM   #10
GBalcom
Much to learn!
 
Join Date: Jun 2012
Location: Georgia
Posts: 428
Thanks: 20
Thanked 4 Times in 4 Posts
GBalcom is on a distinguished road
Re: setting the value (let) of a private class property

ah, ok thanks!

GBalcom 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
Private Property Let statement not allowed within the same class? mdlueck Modules & VBA 7 01-04-2019 02:41 PM
Class module: Pick from a list of possible property values? DB505050 Modules & VBA 6 06-20-2014 06:13 AM
How could VBA class have received an update without executing the Property Let? mdlueck Modules & VBA 11 09-12-2012 06:46 AM
Need help implementing property of base class in derived class. papadilbert Modules & VBA 6 12-01-2011 06:11 AM
Correct syntax to make Class Function Private yet callable by instances of Class mdlueck Modules & VBA 4 11-07-2011 07:32 AM




All times are GMT -8. The time now is 08:32 AM.


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