Property Let

used to change the (or assign) the value of a class property.
This statement lets you define a procedure that assigns a value to a property.
If you want to have full control when a property is initialised you can define the property using a Property Let procedure.

Public Property Let MyProperty() 
End Property

Passing Parameters

It is possible to pass parameters although not best practice.


Public Property Let Department(sDepartment As String) 
     If (sDepartment <> "Sales") And (sDepartment <> "Research") Then
         Err.Raise "This is not a valid department name"
         Exit Property
     End If
     msDepartment = sDepartment
End Property

The following line assigns a department by calling the Property Let procedure

objEmployee.Department = "Sales" 

Hours Per Week

Public Property Let HoursPerWeek(dbHoursPerWeek As Double) 
   mdbNormalHours = WorksheetFunction.Min(35, dbHoursPerWeek)
   mdbOvertimeHours = WorksheetFunction.Max(0, dbHoursPerWeek - 35)
End Property

Write Only Properties

These are not used very often but it is possible to create jus a write-only property
Just provide a property let procedure (no property set)

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext