IT tutorials
 
Office
 

Microsoft Access 2010 : Using the VBA Editor - ANATOMY OF THE VBA EDITOR, USING THE OBJECT BROWSER

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Product Key Free : Microsoft Office 2019 – Serial Number
5/4/2013 8:53:58 PM

1. ANATOMY OF THE VBA EDITOR

You can access the VBA Editor in several ways. From anywhere in Microsoft Access, press Alt+F11 or choose from several places on Access's new Ribbon: Create, Macros, Modules, Database Tools, or Visual Basic. You can also open the VBA Editor by double-clicking a module name in the Navigation Pane or from any form or report. From the Properties dialog box, click the Events tab, select the event that you're interested in, click the Ellipses button (...), and choose Code Builder. When you first view the VBA Editor, you might be a little overwhelmed by the number of components on the screen. Take a look at the VBA Editor within a user-created module, as shown in Figure 1.

The VBA Editor has the following components:

  • Three types of modules: Form or report modules, listed under the Microsoft Access Class Objects, class modules, and standard modules. Each type of component has its own icon. The Project Explorer, shown in Figure 5-1, contains a class module, five standard modules, and two source forms. The VBA project carries the same name as the current database. If the Project Explorer isn't visible when you display the VBA Editor, press Ctrl+R to display it.

    Figure 1.
  • The Properties window: Typically shown in the bottom-left corner of the VBA Editor, the Properties window lists all properties for the currently selected object. The object could be a module or a class module. Although the Properties window is quite helpful for working with user forms in Visual Basic, chances are you won't use it very often when coding in Access. However, it is a handy way to see all the properties for an object, so it's worth checking out — you may find it useful. By clicking the drop-down list you can scroll through the alphabetical listing of the properties for that object.

  • The Code window: This is where you write your code. The Code window displays by default all the subs and functions within the current module. You can limit the display of the code window to only the currently selected procedure by selecting Tools Options and, in the Window Settings frame of the Editor tab, clearing the Default to Full Module View checkbox. Click OK to save your changes. Several components are in the Code window, such as the Object list on the upper left and the Procedure list on the upper right.

  • The Object list box: Provides you with the options to choose from different objects. When you're writing code inside a standard module, the list box contains only the (General) option. When you're writing code in a class module associated with a form or re-port, the Object list box contains an entry for every object (text box, combo box, label, and so on) within that form or report.

  • The Procedure list box: Displays the items corresponding to the type of module you're viewing. When you're viewing a class module associated with a form or report, the Procedure list box shows every event associated with the selected object. For example, if you choose a text box on your form, you will see in the Procedure list box entries for events such as the Click, Enter, Keydown, and Undo, among others.

    If you're viewing a standard module, the list box displays an entry for every sub or function in your module, even the ones that you write or rename. Using the drop-down list is a quick way to select the specific procedure you need to edit. You can then click on the name to open the procedure in the Code window to edit the code behind it.

    When working with a module with lots of objects and procedures, scrolling through the Code window to find the desired procedure can be a time-consuming task. Selecting the object and then clicking the Procedure drop-down box will allow you to quickly navigate to that procedure. Although your code may not list the subs and/or functions alphabetically, you will see that they are listed in ascending order in the drop-down box. You can also use the Procedure drop-down list to jump directly to the General Declaration section.

In addition to these visible components, you can display a number of other components that will help you to write your code and to work with the Access 2010 objects. Most of these components are available under the VBA Editor's View menu.

YOUR DATABASE AND VBA PROJECT — BETTER TOGETHER

You might wonder about the correlation between a VBA project and your database. Quite simply, the database with forms and reports is what you see, and the VBA project contains the instructions to make it work. Although you won't see a separate file, a VBA project exists for every database created in Access. The objects in the Project Explorer shown in Figure 5-1 are present no matter where the code is used in your database. Whether you are writing code behind a form or report or in a module, you see the same objects listed in the Project Explorer.

2. USING THE OBJECT BROWSER

The Object Browser is probably one of the most powerful tools you'll use when writing VBA code. You can display it in the VBA Editor by selecting View => Object Browser or by clicking F2. The Object Browser, shown in Figure 2, has a number of components.

Figure 2.

2.1. Object Browser Components

When you load the Object Browser, you can still view the Project Explorer and the Properties window. The Object Browser appears directly over the Code window. You can return to the Code window at any time by selecting View => Code. When multiple Code windows are open, you can navigate to the desired window by choosing Window from the menu and then selecting the Code window that you want, or press F7 to move the cursor to the Code window. The following are some of the most commonly used components of the Object Browser:

  • The Project/Library box: Shows all the available type libraries. You can choose All Libraries or a specific type library from the drop-down box. The type library you choose impacts which objects you can browse with the Object Browser.

  • The Search box: Use the Search box to search for selected type libraries. After you've entered the search terms click the Search button (the binoculars icon). The results of your search are displayed in the Search Results pane.

  • The Search Results pane: The results of your search are listed in the Search Results pane. You can show or hide it by clicking the Show/Hide icon (two up or down arrows) next to the Search button. The Search Results pane lists the relevant library, class, and member of any object returned by your search. If you click on the object, the full information will be displayed in the Details pane.

  • The Classes list: All the objects, enumerations (enums), and collections in the currently referenced library are displayed in the Classes list. Scrolling through the Classes list you can click to select any of the listed items. After you make the selection, its details appear in the Members Of list and in the Details pane.

  • The Members of classname list: Displays the properties, methods, events, and constants associated with the object currently selected in the Classes list. See the details of a member by selecting it in the Members of classname list.

  • The Details pane of the Object Browser: Information such as the type of object, its data type, the arguments it needs, and the parent library or collection is shown in the Details pane. For example, in Figure 3, the Details pane informs you that the constant vbOKOnly is a member of the enum vbMsgBoxStyle, which is a member of the VBA Object Library. Its value is 0; the other members of the enum vbMsgBoxStyle include vbInformation, vbOKCancel, and vbYesNo.

    Figure 3.

When a Help file is associated with the currently selected object, you can display a Help topic by selecting the item in either the Classes or Members list, and then pressing F1 or clicking the Help button in the upper-right corner of the Object Browser.

Use the buttons next to the Project/Library box to scroll through the previous or next members of the current collection.

One of the advantages of the Object Browser is that you can actually use it to take you to anywhere in the code that the current object is declared. For example, in Figure 3 the current database's Object Library (SAG_Functions) is searched for the procedure CoffeeTime. The Search Results pane lists the library, class, and member for the CoffeeTime sub. You can click the View Definition button (the fourth button from the left, next to the Project Library drop-down box) to return to the Code window and display the CoffeeTime sub.

2.2. Show Hidden Members

You can show the hidden members in the Object Browser by right-clicking on the Object Browser and selecting Show Hidden Members. When listed, the Hidden Members will appear in a light gray text  because they are not intended for you to use within your code. However, when you want or need to know more about them, the Object Browser can be a convenient resource. By selecting one of the objects, you can get more information about it, such as what library it belongs to, the members of the class, and the argument and data type (listed in the bottom of the window).

To hide them again, you merely right-click on the Object Browser, and deselect Show Hidden Members from the pop-up menu.

 
Others
 
- Microsoft Visio 2010 : Connecting Shapes - Understanding Visio Connectors (part 2) - Connecting to Shapes versus Points on Shapes
- Microsoft Visio 2010 : Connecting Shapes - Understanding Visio Connectors (part 1) - Connecting Basics
- Microsoft PowerPoint 2010 : Working with Animation and Transitions - Setting Slide Transitions
- Microsoft PowerPoint 2010 : Finalizing Your Slide Show - Rehearsing Your Presentation
- Microsoft Project 2010 : Creating Master Schedules with Inserted Projects - Reporting and Analyzing Across Projects
- Microsoft Project 2010 : Creating Master Schedules with Inserted Projects - Critical Path Across Projects
- Microsoft Excel 2010 : Linking a Cell to Smart Art
- Microsoft Excel 2010 : Inserting SmartArt Images
- Microsoft Excel 2010 : SmartArt
- Microsoft Word 2010 : Managing Word Page Layouts - Adding Headers and Footers
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us