Access Vba Property

While Property Get retrieves a value of a class property, the Property Let procedure sets the value. For example, the following code is the Dogs Property Let procedure from our Kennel class example. It is constructed in the same way as the Property Get procedure, but using the Let keyword.

Public Property Let Dogs(intNewValue As Integer)

mintDogs = intNewValue End Property

You can declare its arguments' data types according to your needs, and you can even rename the argument as you would with any other procedure argument. In fact, you can declare more than one argument if you need to—just like any other procedure.

Property Let procedures work differently to standard procedures, and it may take a little getting used to. When VBA code assigns a value to the property, like so:

myKennel.Dogs = intSomeVariable

The code inside passes the argument to the privately declared property mintDogs. Just like the Property Get procedure, you can declare more than one argument in Property Let. For example, if we declare our procedure like so:

Public Property Let Dogs(strColor As String, intNewValue As Integer) ' Code that uses the strColor argument mintDogs = intNewValue End Property

We can refer to it like this:

myKennel.Dogs("black") = intSomeVariable Notice that the property value being passed must be the last argument in the list.

0 -1

Post a comment