Home

Changing Form Controls with VBA in Access 2013

|
|  Updated:  
2016-03-26 15:42:03
Access Forms and Reports For Dummies
Explore Book
Buy On Amazon

When an Access 2013 database form is open, you can use VBA code to change the contents and even the appearance of the form, from the big picture down to the individual controls.

Suppose that you have a form that includes a control for choosing a payment method. When the user chooses a payment method, you want to enable or disable other controls on the form based on the selected payment method. Alternatively, you may want to autofill some other controls on the form or even make some controls visible or invisible, depending on which payment method the user selected.

Within VBA, use the following syntax to change a control’s property:

ControlName.PropertyName = Value

ControlName is the complete name of a control on an open form, PropertyName is the name of the property that you want to change, and Value is the new value for the property. A dot separates the control name from the property name. The complete name means that the name has to contain both the name of the form and the name of the control. In a class module, however, you can use the keyword Me to stand for the form name. The keyword Me means “the form to which this class module is attached.”

About This Article

This article is from the book: 

About the book author:

Alison Barrows is the author or coauthor of several books about Access, Windows, and the Internet. Joseph Stockman is an 18-year software designer who has authored or coauthored five Access programming books. Allen Taylor is a 30-year veteran of the computer industry and the author of over 20 books.

Joe Stockman is an independent consultant, software designer, and author who has been using Microsoft Access since its initial release. He’s also developed courseware and taught classes in Access and VBA. Joe developed his first application in Access, and then migrated into Visual Basic and VB.NET, where he specializes in creating applications for the Windows Mobile platform. He worked for several software companies before forming his consulting business in 2002, where he deals with all types of clients including healthcare, financial, government, manufacturing, and small business. His ability to turn his customers’ wishes into working applications keeps them satisfied. Joe’s also writing the fundamentals column for the Advisor Guide to Microsoft Access magazine.

Allen G. Taylor is a 30-year veteran of the computer industry and the author of over 40 books, including SQL For Dummies and Crystal Reports For Dummies. He lectures nationally on databases, innovation, and entrepreneurship. He also teaches database development internationally through a leading online education provider.