devxlogo

Create Custom Properties For Forms or Class Modules

Create Custom Properties For Forms or Class Modules

Have you ever wanted to push a variable onto a form without using atag? Property functions let you create custom properties for forms or classmodels. Use PropertySet, PropertyGet, and PropertyLet statements to manipulatecustom properties. For example, you want to send a key value to a form so that the keyis there in time for an SQL query to use it in a condition. Include a variabledeclaration for the property as a form-level variable:

 Private msKey as String

Then add two procedures for PropertySet and PropertyLet for the form:

 Public Property Let GetKey(vNewValue)	msKey = vNewValueEnd PropertyPublic Property Get GetKey()	GetKey = msKeyEnd Property

You can now set the property from elsewhere by using:

 Form1.GetKey = "David"

In your form, use the variable you declared for any usage in your code.Property Procedures can be a bit more complex. But, the point is that theVB4 has become much more adaptable to your needs. Customize it to fit.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist