Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Understanding Scope and Variables - Pg. 148

Using Visual Basic to Automate Your Database 2. 3. Add code to the module, and then save and name the module. To modify a module, select the module in the Database window, and then click Design. 148 Opening the Visual Basic Editor Access provides several ways to open the Visual Basic Editor. If you have a form or report open in Design view, click the Code button on the toolbar to open the Visual Basic Editor and display that object's class module. To view or create an event procedure for a control on a form or a report, right-click the control in Design view, choose Properties on the shortcut menu, and then click the Events tab. Click in the property box for the event for which you want to create a procedure, select Event Procedure from the drop-down list, and then click the event's Build button. For a control such as a command button, you can right-click the control, and then click Build Event. Understanding Scope and Variables In this section, we'll cover some concepts you need to keep in mind when you're writing event procedures, functions, and other procedures for a database. We'll look at scope, which governs how much access you have to a procedure and the variables you declare and lifetime, which describes how long a variable is active, and we'll look at some rules and practices for declaring variables in a program. Working with Scope The declaration for the Import procedure starts with the term Private, as shown here: Private Sub cmdImport_Click()