These are referred to as class methods, and providing they have been created using the PUBLIC keyword (as opposed to PRIVATE), they can be called from outside the class module after the object has been instantiated. To do this, we add SUBs and FUNCTIONs to the class module. As written above, we can also process and work with those property values in all kinds of ways.
The screenshot below shows all the class module code to set and get the clsPerson properties:Īdding SUB's and FUNCTION's to the Class ModuleĬlass modules and objects are not just about storing and retrieving property values. The Age and Gender properties in the clsPerson class are set and retrieved in the same way. It works in a similar way to calling a VBA FUNCTION. As such, " Name = strName" assigns the value stored in the strName class module variable to the objects Name property and returns this value whenever the object's Name property is referenced outside of the class module. PROPERTY GET returns a returns the value of the property by assigning a value to NAME. For example, to retrieve the property value and store it in a variable called strGetName we would use the following code:ĭoing this invokes PROPERTY GET NAME in the clsPerson class module (see code snippet above). Then to retrieve the value of the objects Name property from outside the class module, we just need to reference the object name (eg objPerson) and property (eg Name) in the same way. Hence, we may reuse the code we write in the class module over and over again. Once the class module is in place, we can create as many instances, or objects based on the module, as we need. The second step is to create the actual object based on the class module - this is known as instantiation. To do this we create what is known as a Class Module. The first is to create a blueprint or design for the object which defines what information the object holds and the processing to be done on that information. There are two steps to creating a custom object. The advantage of creating a custom object is that a lot of related information, and the means to process it, is contained within a referenced entity that is easily accessed and used from different parts of the program. The best way to do this would be to create our own custom person object with the above-mentioned variables as the object's properties, and any code to process or work with these properties, as the object's methods. The information we want to store and process may include the person's name, age and gender. Let's say these variables relate to a person. Suppose we wanted to work with a set of related variables with VBA code. I have added some data to demonstrate how information contained in the Option Button Group is stored in the database. The screenshot below shows the finished form with the underlying table. The form should now be ready to open in FORM VIEW. (showing the option value property) is also visible. The property sheet for the third control button
Repeat steps 4 and 5 for the remaining two CONTROL BUTTONS checking the OPTION VALUE properties say "2" and "3" respectively.ĭesign grid showing three option buttons added to the.This is the value that will be bound to the team field if the button is selected by the user at runtime.
And drag it down onto the form design grid.