Using Microsoft Office XP Developer Add-Ins

3 4

Microsoft Office XP Developer includes a number of advanced add-ins for developers. Office XP Developer includes utilities for working with VBA code, creating file packages for distributing databases you develop, and coordinating development work for a development tool, among others. You access these add-ins via the Add-Ins menu of the Visual Basic Editor.

Even if you’ve installed the Office Developer Tools component of Office XP Developer, you might not see all of the add-ins on the Add-Ins menu, because they must be loaded first. You can see the available Visual Basic Editor add-ins in the Add-In Manager dialog box, and for each one, you can set its load properties. For example, if you want to have the Code Commenter And Error Handler Add-In always loaded at startup in the Visual Basic Editor, follow these steps:

  1. Display the Visual Basic Editor, if necessary, by pressing Alt+F11.
  2. Choose Add-Ins, Add-In Manager. The Add-In Manager dialog box will appear.
  3. In the Add-In Manager dialog box, select that add-in, select the Load On Startup check box, and also select the Loaded/Unloaded check box to load the add-in immediately.

If you don’t want an add-in to always be loaded because you use it only occasionally (the Packaging Wizard is an example), you can select the Loaded/Unloaded check box to load it for the current session only. Figure 15-22 shows the Add-In Manager dialog box with the Code Commenter And Error Handler and Multi-Code Import/Export add-ins loaded and set to load on startup and the Packaging Wizard loaded for the current session only.

figure 15-22. the add-in manager dialog box lets you set startup and load options for various visual basic editor add-ins.

Figure 15-22. The Add-In Manager dialog box lets you set startup and load options for various Visual Basic Editor add-ins.

caution


Don’t confuse the Add-Ins menu and the Add-In Manager dialog box in the Visual Basic Editor with the similarly named menu and dialog box in the Access window. The menu and dialog box in Access are used to manage Access add-ins, and those in the Visual Basic Editor are used to manage Visual Basic Editor add-ins.

Troubleshooting - I can’t find the Code Librarian

The Code Librarian, one of the Office Developer Tools in Office XP Developer, was available from the Add-Ins menu in the Access 2000 Visual Basic Editor. It’s now a separate Developer Application, which you can select from the Microsoft Office XP Developer program group.

Using the Code Commenter and Error Handler Add-In to Enhance Your VBA Code

The Code Commenter And Error Handler add-in combines two separate add-ins: It inserts a comment header section and a standard error handler into procedures using a customizable template (EHT file). To use the Code Commenter And Error Handler add-in, follow these steps:

  1. Display the Visual Basic Editor, if necessary, by pressing Alt+F11.
  2. In the Visual Basic Editor, choose Add-Ins, Code Commenter And Error Handler Add-In. The dialog box shown in Figure 15-23 will appear.

    figure 15-23.the code commenter and error handler add-in dialog box lets you add comments and error handlers to vba code.

    Figure 15-23. The Code Commenter And Error Handler Add-In dialog box lets you add comments and error handlers to VBA code.

  3. Specify how you want the template to be applied. You can apply the template to the current procedure only, to all procedures in the current module, or to all procedures in the current project.
  4. In the Name and Initials text boxes in the Author section, enter your name and initials as you want them to appear in the comments section of your code.
  5. Click Apply. The add-in will apply the template you selected.

Figure 15-24 shows the Comments header block of a procedure after the standard template has been applied.

figure 15-24. this comments header block was inserted by the code commenter and error handler add-in.

Figure 15-24. This Comments header block was inserted by the Code Commenter And Error Handler add-in.

The error hander inserted by the add-in is shown in Figure 15-25.

figure 15-25. this error handler was inserted by the code commenter and error handler add-in.

Figure 15-25. This error handler was inserted by the Code Commenter And Error Handler add-in.

note


If a procedure already has an error handler, selecting the Code Commenter And Error Handler add-in will do nothing.

The error handler is in the form of a Select Case statement with only Case Else filled in. You can insert other Case statements as needed to deal with specific errors.

Speeding Up Importing and Exporting Using the Multi-Code Import/Export Add-In

The Multi-Code Import/Export add-in allow you to import or export a number of objects in one pass, which can save a good deal of time. To import objects, follow these steps:

  1. On the Add-Ins menu, click Multi-Code Import to open the Multi-Code Import dialog box.
  2. Click Browse to open the Select Files To Import dialog box, in which you can select various types of saved code files to import into a VBA project—standard modules (BAS), class modules (CLS), designers (DSR), and UserForms (FRM), although the latter selection is not useful for Access. You can use the standard keys to select as many files as you want.
  3. Click Open to return to the Multi-Code Import dialog box. The selected files will be listed. You can remove one or more files using the Remove button. When the list accurately represents the files you want to import, click the Import button to start the import.

Figure 15-26 shows some modules imported in the Project Explorer pane.

figure 15-26. two newly imported modules are shown in the project explorer pane.

Figure 15-26. Two newly imported modules are shown in the Project Explorer pane.

InsideOut

Although Access form and report modules are class modules and they appear in the Select Files To Import dialog box, you can’t import them using the Multi-Code Import dialog box. When you import a form or a report in the Access interface, its class module (if any) will also be imported.

To use the Multi-Code Export add-in, follow these steps:

  1. On the Add-Ins menu, click Multi-Code Export to open the Multi-Code Export dialog box (shown in Figure 15-27).

    figure 15-27.you select multiple files to export in the multi-code export dialog box.

    Figure 15-27. You select multiple files to export in the Multi-Code Export dialog box.

  2. Select the standard modules or class modules you want to export, and then select a folder to which the files should be saved. Click the Export button to start the export of the selected files. (All the files in the Selected Objects list will be exported.)

    note


    There’s little point in exporting Access form or report class modules because they can’t be imported—and, in any case, you get the code module along with the form when you import an Access form into another database.

  3. The Multi-Code Export Results dialog box will appear, showing you the status of the export and telling you that the export was successful. Click OK to close the dialog box.

Constructing String Expressions Using the VBA String Editor Add-In

The VBA String Editor add-in automatically inserts quotation marks, carriage return constants, and other syntactical elements into strings, which saves you time and reduces errors (such as a missing set of quotation marks). This add-in is useful for constructing strings to be displayed in message boxes or strings to be printed in the Immediate window by Debug.Print statements.

To work with this utility, follow these steps:

  1. Press Alt+F11 to display the Visual Basic Editor, if needed.
  2. Choose Add-Ins, VBA String Editor. The dialog box shown in Figure 15-28 will appear.

    figure 15-28.the vba string editor dialog box offers several toolbar buttons for working with string expressions.

    Figure 15-28. The VBA String Editor dialog box offers several toolbar buttons for working with string expressions.

  3. Type or paste a string into the dialog box. You might want to use one of the first three buttons on the toolbar (which are standard Cut, Copy, and Paste buttons).
  4. Indicate which components of the string are variables by selecting each variable in turn and clicking the Toggle To String button. The variables will appear as blue, boldface text, as shown in Figure 15-29.

    figure 15-29.the vba string editor indicates variables in a string using blue, boldface type.

    Figure 15-29. The VBA String Editor indicates variables in a string using blue, boldface type.

  5. Click the Update button, and the VBA String Editor will add quotation marks as needed. For example, the string

    FirstName LastName lived at StreetAddress on OrderDate 

    from Figure 15-29 becomes

     FirstName & " " & LastName & " lived at " & StreetAddress & _ " on " & OrderDate 

The VBA String Editor does an excellent job on simple expressions like this one, but it might not be able to process more complex expressions properly, particularly those that need nested quotes. For example, the editor translates this string:

 strCriteria = [fldTaskID] = intTaskID And [fldProjectKey] _     = strProjectKey And [fldTaskConsultant] = strResource 

into the following string:

 strCriteria  & " = [fldTaskID] = " & intTaskID _              & " And [fldProjectKey] = "  & strProjectKey _              & " And [fldTaskConsultant] = "  & strResource 

Instead, it should have been translated into the following expression (because the string variables need to be surrounded with quotation marks):

 strCriteria = "[fldTaskID] = " & intTaskID & " And _     [fldProjectKey] = '" & strProjectKey & "' And _     [fldTaskConsultant] = '" & strResource & "'" 

Even though it might not parse an expression perfectly, the VBA String Editor takes a good deal of the pain out of formatting complex expressions in VBA code.

Other Office XP Developer Tools

Office XP Developer includes a Packaging Wizard, which helps you prepare distributed applications. (This add-in is covered in Appendix B, "Distributing Your Access Application.") It also includes Microsoft Visual SourceSafe, which is used to implement source code control and allows multiple developers to work on an application without overwriting each other’s work. If you have Visual SourceSafe version 6.0 or later installed, you can use the VBA Source Code Control add-in to help implement source control.



Microsoft Access Version 2002 Inside Out
Microsoft Access Version 2002 Inside Out (Inside Out (Microsoft))
ISBN: 0735612838
EAN: 2147483647
Year: 2005
Pages: 172
Authors: Helen Feddema

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net