Declares the name, arguments, and code that form the body of a Property Let procedure, which assigns a value to a property.
[Public | Private][Static] Property Let name [(arglist)]
[statements]
[Exit Property]
[statements]
End Property
The Property Let statement syntax has these parts:
Part |
Description |
Public |
Indicates that the Property Let procedure is accessible to all other procedures in all modules. If used in a private module (one that contains an Option Private statement), the procedure is not available outside the project. |
Private |
Indicates that the Property Let procedure is accessible only to other procedures in the module where it is declared. |
Static |
Indicates that the Property Let procedure’s local variables are preserved between calls. The Static attribute doesn’t affect variables that are declared outside the Property Let procedure, even if they are used in the procedure. |
name |
Name of the Property Let procedure; follows standard variable naming conventions, except that the name can be the same as a Property Get or Property Set procedure in the same module. |
arglist |
List of variables representing arguments that are passed to the Property Let procedure when it is called. Multiple arguments are separated by commas. The name and data type of each argument in a Property Let procedure (except the last one) must be the same as the corresponding arguments in a Property Get procedure. The last argument is the value assigned to the property on the right-hand side of an expression. The data type of the last (or sometimes the only) argument must be the same as the return type of the corresponding Property Get procedure. |
statements |
Any group of statements to be executed within the body of the Property Let procedure. |
The arglist argument has the following syntax and parts:
[ByVal | ByRef] varname[( )][As type]
Part |
Description |
ByVal |
Indicates that the argument is passed by value. |
ByRef |
Indicates that the argument is passed by reference. |
varname |
Name of the variable representing the argument; follows standard variable naming conventions. |
type |
Data type of the argument passed to the Property Let procedure; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Date, String (variable length only), Object, Variant, a user-defined type, or an object type. |
Note Every Property Let statement must define at least one argument for the procedure it defines. That argument (or the last argument if there is more than one) contains the actual value to be assigned to the property when the procedure defined by the Property Let statement is invoked.
If not explicitly specified using either Public or Private, Property procedures are public by default. If Static is not used, the value of local variables is not preserved between calls.
All executable code must be in procedures. You can’t define a Property Let procedure inside another Property, Sub, or Function procedure.
The Exit Property keywords cause an immediate exit from a Property Let procedure. Program execution continues with the statement following the statement that called the Property Let procedure. Any number of Exit Property statements can appear anywhere in a Property Let procedure.
Like a Function and Property Get procedure, a Property Let procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. However, unlike a Function and Property Get procedure, both of which return a value, you can only use a Property Let procedure on the left-hand side of a property assignment expression or Let statement.
Function Statement, Let Statement, Property Get Statement, Property Set Statement, Sub Statement.
You can use the Property Let statement to define a property procedure that assigns the value of a property for a user-defined object. You will probably want to use the Property Let and Property Get statements together to create a property for an object. For example, you could define a Property Let procedure in a form module to set a new property for an object, and a Property Get procedure to return the value of that setting.
Usually you will define property procedures within a form module or report module. Property procedures in a form or report module are public by default, and will be available to procedures in other modules in the current database. However, they will not be available to other databases.
You can use the property procedures to create new properties on a user-defined object. You can also use them to combine a set of properties for a custom form or report object. For example, you could create a custom property called CustomFormType. Using the Property Get statement, you could construct the CustomFormType property procedures so that one setting would display a white form with scroll bars, navigation buttons, and caption “Type1”, while another setting would display a blue form with neither scroll bars nor navigation buttons, and caption “Type2”. Then you could set the CustomFormType property for new form objects that you create for this form. Using the Property Get statement, you could create a property procedure to return the value of this property once it has been set.
This example uses the Property Let statement to define a procedure that assigns a value to a property. The property identifies the pen color for a drawing package.
Dim CurrentColor As IntegerBLACK = 0, RED = 1, GREEN = 2, BLUE = 3 ' Set the pen color property for a Drawing package. ' The module-level variable CurrentColor is set to ' a numeric value that identifies the color used for drawing.Let PenColor(ColorName As String) Select Case ColorName ' Check color name string. Case "Red" CurrentColor = RED ' Assign value for Red. Case "Green" CurrentColor = GREEN ' Assign value for Green. Case "Blue" CurrentColor = BLUE ' Assign value for Blue. Case Else CurrentColor = BLACK ' Assign default value. End SelectProperty ' The following code sets the PenColor property for a drawing package ' by calling the Property Let procedure.() = "Red"
See also the Property Get statement example.