Microsoft Office Tutorials and References
In Depth Information
Chapter 4: Controlling Forms with VBA
Chapter 4: Controlling Forms
with VBA
In This Chapter
Displaying and responding to custom messages
Opening a form with the DoCmd object
Making changes in form controls
Using objects and collections in code
When you create a database for other people to use, making things as
automatic as possible is to your advantage. The more automated
your overall database is, the less likely users — the people who actually
use the database — are to make mistakes (even if one of those users is
you!). This chapter explores some techniques for using Visual Basic for
Applications (VBA) to display custom messages to users, to automatically
open and close forms, to change form controls, and more.
Displaying Custom Messages
In your day-to-day work with your computer, programs occasionally pop
little messages onscreen to ask you questions, such as “Are you sure
you want to delete . . .?” You can click the Yes or OK button to
delete, or click the No or Cancel button to change your mind. You can add
similar custom messages to your database.
Displaying a message box
As we discuss in Chapter 2 of this minibook, VBA can display custom
messages. By using a variable and the MsgBox() function, you can display a
question and then have VBA perform some task based on the user’s answer
to that question. The syntax for creating such an interactive message box is
Dim myVar as Byte
myVar = MsgBox( prompt [, buttons ] [, title ])
The Dim statement defines a variable as the Byte data type — a number in
the range of 0 to 255. myVar is any variable name of your choosing, prompt
Search JabSto ::




Custom Search