setting the value (let) of a private class property (1 Viewer)

GBalcom

Much to learn!
Local time
Yesterday, 17:07
Joined
Jun 7, 2012
Messages
459
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?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:07
Joined
May 21, 2018
Messages
8,463
You did not do anything incorrect. That is a dumb shortcoming of VBA. I think you can make a private function.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:07
Joined
May 7, 2009
Messages
19,169
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")
 

GBalcom

Much to learn!
Local time
Yesterday, 17:07
Joined
Jun 7, 2012
Messages
459
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:07
Joined
May 7, 2009
Messages
19,169
yes, you can do it in Public sub/func init().
then from init() you can call your Let Company property.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:07
Joined
May 21, 2018
Messages
8,463
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.
 

GBalcom

Much to learn!
Local time
Yesterday, 17:07
Joined
Jun 7, 2012
Messages
459
I read it, but I don't understand how to call it, without the keyword me. what is ObjAppSettings?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:07
Joined
May 21, 2018
Messages
8,463
call without Me should work.
CompanyName = .Fields("NAME")
instead of
me.CompanyName = .Fields("NAME")
 

Users who are viewing this thread

Top Bottom