Chapter 30. Using Builders, Wizards, and Menu Add-Ins

Defining Builders, Wizards, and Menu Add-Ins

Add-ins are tools that extend the functionality of Access. They enhance the Access environment by making difficult tasks easier, automating repetitive tasks, and adding enhanced functionality. You can design add-ins for yourself or for others in your organization to use. You even might want to distribute add-ins as part of your application so that your users can build their own database objects. If you are really ambitious, you might decide to build an add-in for sale in the Access third-party market.

Microsoft Access supports three types of add-ins: builders, wizards, and menu add-ins. Each has its own advantages and uses. When you begin the process of designing an add-in, you must decide whether it will be a builder, wizard, or menu add-in. This decision affects how you design the add-in as well as how you install it. This chapter defines and shows you how to design and install each type of add-in.

Using Builders

A builder is an add-in that helps users construct an expression or another data element. Builders most often are used to help users fill in a property of a database object. Builders generally consist of a single dialog box that appears after the user clicks the ellipsis to the right of the property on the Property sheet. An example of a builder is the expression builder that appears when users are setting the control source of a text box on a form. Access supports three types of builders:

  • Property builders

  • Control builders

  • Expression builders

Looking At Design Guidelines

When designing your own builder, you should be consistent with the builders that are part of Access. You therefore must learn about the standards for an Access builder. To design builders that are consistent with the built-in builders, keep a few guidelines in mind:

  • Set the AutoCenter property of the Builder form to Yes.

  • Remove record selectors and navigation buttons.

  • Remove scroll bars.

  • Be consistent about the placement of objects on the form. Place the OK and Cancel buttons in the same place in each builder you create, for example.

  • Design the forms as dialog boxes.

Creating a Builder

Now that you are familiar with some general design guidelines for builders, you are ready to design your first builder. What a builder does is completely up to your imagination. For illustration, this section begins with a simple builder that prompts users to select the special effect for a text box. Three overall steps are required to create the builder:

  1. Write a builder function.

  2. Design a builder form.

  3. Register the builder.

The following sections go over each of these steps in detail.

Writing a Builder Function

The builder function is the function Access calls each time the builder is launched. It launches the builder form and then returns a value to the appropriate property. Listing 30.1 is an example of a builder function. It is located in CHAP30LIB.MDA in the basBuilders module on the accompanying CD-ROM.

Example 30.1. Using a builder function.

Function SpecialEffect(strObject As String, _
            strControl As String, _
            strCurrentValue As String)

   On Error GoTo SpecialEffect_Err
   DoCmd.OpenForm FormName:="frmSpecialEffect", _
                  WindowMode:=acDialog, _
                  OpenArgs:=strCurrentValue
   If SysCmd(acSysCmdGetObjectState, acForm, _
            "frmSpecialEffect") = acObjStateOpen Then
      Select Case Forms!frmSpecialEffect!optSpecialEffect.Value
         Case 1
            SpecialEffect = "Flat"
         Case 2
            SpecialEffect = "Raised"
         Case 3
            SpecialEffect = "Sunken"
         Case 4
            SpecialEffect = "Etched"
         Case 5
            SpecialEffect = "Shadowed"
         Case 6
            SpecialEffect = "Chiseled"
      End Select
      DoCmd.Close acForm, "frmSpecialEffect"
   Else
      SpecialEffect = strCurrentValue
   End If

SpecialEffect_Exit:
   Exit Function
SpecialEffect_Err:
   MsgBox "Error # " & Err.Number & ": " & Err.Description
   Resume SpecialEffect_Exit
End Function

A builder function must receive three preset arguments and must return the value that will become the value for the property being set. The three preset arguments follow:

  • strObject: The name of the table, query, form, report, or module on which the builder is operating.

  • strControl:  The name of the control to which the property applies.

  • strCurrentValue: The current property value.

Although the names of the arguments are arbitrary, their data types, positions, and content cannot be changed. Access automatically fills in the values for the three arguments.

The SpecialEffect function opens the form called frmSpecialEffect. It opens the form in Dialog mode, passing it the current value of the property as the OpenArgs value. Figure 30.1 shows the frmSpecialEffect form.

The Special Effect builder form.

Figure 30.1. The Special Effect builder form.

The following code is located in the Click event of the cmdOkay command button on the form:

Private Sub cmdOK_Click()
   Me.Visible = False
End Sub

Notice that the code sets the Visible property of the form to False. The code placed behind the cmdCancel command button looks like this:

Private Sub cmdCancel_Click()
   DoCmd.Close
End Sub

This code closes the frmSpecialEffect form.

After the user clicks OK or Cancel, the code in the SpecialEffect function continues to execute. The function uses the SysCmd function to determine whether the frmSpecialEffect form is loaded. You also can use the user-defined IsLoaded function to accomplish this task. If the frmSpecialEffect form still is loaded, the user must have selected a special effect and clicked OK. Because the form still is open, the function can determine which option button the user selected.

The Case statement in the SpecialEffect function evaluates the value of the optSpecialEffect option button found on the frmSpecialEffect form. It sets the return value for the function equal to the appropriate string, depending on the option button that the user of the builder selects. If the user of the builder selects the second option button (with a value of 2), for example, the SpecialEffect function returns the string "Raised". After the option button value is evaluated and the return value is set, the frmSpecialEffect form no longer is needed, so it is closed.

If the user chooses Cancel from the frmSpecialEffect form, the SysCmd function returns False, and the return value of the SpecialEffect function is set equal to strCurrentValue, the original property value. The property value therefore is not changed.

Designing a Builder Form

Although you have seen the code behind the Click event of the OK and Cancel buttons on the frmSpecialEffect form, you have not learned about the design of the form or the idea behind this builder. Ordinarily, when the Special Effect property is set from the Property window, no wizard exists to assist with the process. Although the process of setting the Special Effect property is quite simple, the main problem is that it is difficult to remember exactly what each special effect looks like. The custom special effect builder is designed with this potential problem in mind. It enables users of the builder to see what each special effect looks like before deciding which effect to select.

The properties of the form are quite simple. The Modal property of the form is set to Yes. The record selectors, navigation buttons, and scroll bars have been removed. The AutoCenter property of the form has been set to True. Six text boxes have been added to the form. The special effect of each text box has been set to a different style. An option group has been added to the form. This group has a different value, depending on which option button was selected. The Default property of the OK command button has been set to Yes, making the OK button the default choice. The Cancel property of the Cancel command button was set to Yes, ensuring that if the user presses Esc, the code behind the Cancel button executes. The code behind the Click events of the OK and Cancel buttons was shown in the preceding section. Listing 30.2 shows one more piece of code that enhances this builder.

Example 30.2. Enhancing the builder.

Private Sub Form_Load()
   'Set the Value of the Option Group
   'To the Current Value of the Property
   Select Case Me.OpenArgs
         Case "Flat"
            Me!optSpecialEffect.Value = 1
         Case "Raised"
            Me!optSpecialEffect.Value = 2
         Case "Sunken"
            Me!optSpecialEffect.Value = 3
         Case "Etched"
            Me!optSpecialEffect.Value = 4
         Case "Shadowed"
            Me!optSpecialEffect.Value = 5
         Case "Chiseled"
            Me!optSpecialEffect.Value = 6
End Select
End Sub

This subroutine is placed in the Load event of the builder form. It sets the value of the option group to the current value of the property (passed in as an OpenArg).

Although the frmSpecialEffect form is not particularly exciting, it illustrates quite well that you can design a form of any level of complexity to facilitate the process of setting a property value. So far, though, you have not provided an entry point to the builder. If you select the Special Effect property, no ellipsis appears. You do not yet have access to the builder.

Registering a Builder

Before you can use a builder, you must register it. You can register a builder in two ways:

  • Manually add the required entries to the Windows Registry.

  • Set up the library database so that the Add-In Manager can create the Windows Registry entries for you.

Manually Adding Entries to the Windows Registry

Adding the required entries to the Windows Registry involves four steps:

  1. If no Registry key exists for the property for which you are designing a builder, add the property as a subkey under Property Wizards.

  2. Add an additional subkey for the builder.

  3. Add four predefined Registry values for the key.

  4. Set the proper data value for each value name.

The four value names that must be created for the subkey are Can Edit, Description, Function, and Library. Table 30.1 describes these value names for the Registry subkey.

Table 30.1. Values for the Registry subkey.

Value NameValue TypePurpose
Can EditDWORDAllows the builder to operate on and modify an existing value.
DescriptionStringSpecifies a description that appears in the dialog box, which is invoked automatically if more than one builder exists for a property.
FunctionStringName of the builder function.
LibraryStringName of the library containing the builder function.

Now that you have an overview of the steps involved in the process, you are ready to walk through the steps in detail. The following steps set up the builder called SpecialEffect, which is contained in the library database CHAP30LIB.MDA in the folder c:AccessLibs:

  1. To invoke the Registry Editor, choose Start | Run from the task bar. Type regedit and click OK. This invokes the Registry Editor.

  2. Locate the HKEY_LOCAL_MACHINESOFTWAREMicrosoftOffice8.0AccessWizardsProperty Wizards key, as shown in Figure 30.2.

    The Property Wizards Registry key.

    Figure 30.2. The Property Wizards Registry key.

  3. Determine whether a subkey exists with the name of the property for which you are creating a builder (in this case, SpecialEffect). If so, skip to step 6.

  4. Choose Edit | New | Key.

  5. Type the property name as the name for the new key (in this case, SpecialEffect).

  6. With the new key selected, choose Edit | New | Key again.

  7. Type a descriptive name for your builder (in this case, SpecialEffectBuilder).

  8. Choose Edit | New | DWORD Value.

  9. Type Can Edit as the value name.

  10. Choose Edit | New | String Value.

  11. Type Description as the value name.

  12. Choose Edit | New | String Value.

  13. Type Function as the value name.

  14. Choose Edit | New | String Value.

  15. Type Library as the value name.

  16. Double-click the Can Edit value name. The Edit DWORD Value dialog box appears, as shown in Figure 30.3.

    The Edit DWORD Value dialog box.

    Figure 30.3. The Edit DWORD Value dialog box.

  17. Enter 1 for the value data and click OK.

  18. Double-click the Description value name. The Edit String dialog box appears, as shown in Figure 30.4.

    The Edit String dialog box.

    Figure 30.4. The Edit String dialog box.

  19. Enter the description you want the user of the builder to see if more than one builder is assigned to the property (in this case, Special Effect Builder).

  20. Double-click the Function value name. Enter the name of the builder function (in this case, SpecialEffect).

  21. Double-click the Library value name. Enter the name and location of the library database (in this case, c:AccessLibsChap30Lib.MDA). You do not have to enter the path if the library is located in the Access folder.

Figure 30.5 shows the completed Registry entries. The builder now should be ready to use. To test the builder, you need to exit and relaunch Access. If all the Registry entries are created successfully, you can use the builder. To test the builder, open any database (not the library database), create a new form, and add a text box. Select Special Effect from the Format tab of the Properties window. An ellipsis appears to the right of the Special Effect drop-down list, as shown in Figure 30.6. If you click the ellipsis, the builder form appears. Select a special effect and click OK. The special effect you selected now appears in the Special Effect property.

The completed Registry entries required to add the builder.

Figure 30.5. The completed Registry entries required to add the builder.

Using the custom builder.

Figure 30.6. Using the custom builder.

Note

If you do not follow exactly the format for the value names, the message Invalid add-in entry for 'SpecialEffectBuilder' appears, as shown in Figure 30.7. You must correct the Registry entry.

This error message appears if the Registry entry is invalid.

Figure 30.7. This error message appears if the Registry entry is invalid.

Automating the Creation of Registry Entries

The alternative to editing the Windows Registry manually is to set up the library database so that the Add-In Manager can create the Registry entries for you. This involves adding a table to the library database. The table must be called USysRegInfo. Follow these steps:

  1. Tables that begin with USys or MSys are considered system tables and by default are hidden. The first step is to show system tables. With the library database open, choose Tools | Options. From the View tab, click System Objects. Click OK. Figure 30.8 shows the Tables tab.

    The Tables tab with system objects visible.

    Figure 30.8. The Tables tab with system objects visible.

  2. The next step is to import an existing USysRegInfo table. To do this, right-click the Tables tab in the Database window and select Import. Using the Import dialog box, move to the folder where Access is installed and locate the WZMAIN80.MDA file. This is a library file that ships with Access. Select the WZMAIN80.MDE file and click Import.

  3. The Import Objects dialog box appears, as shown in Figure 30.9. Locate and select the USysRegInfo table and click OK. A copy of the USysRegInfo table is added to your library database.

    Using the Import Objects dialog box to add the USysRegInfo table to your library database.

    Figure 30.9. Using the Import Objects dialog box to add the USysRegInfo table to your library database.

  4. Double-click to open the USysRegInfo table in the Database window.

  5. Delete any existing entries in the table.

  6. Specific entries must be added to the USysRegInfo table. Figure 30.10 shows these entries, and Table 30.2 explains them. Add the entries and close the table.

    The completed table with entries for Registry.

    Figure 30.10. The completed table with entries for Registry.

  7. Open the database that references the add-in.

  8. Choose Tools | Add-Ins | Add-In Manager. The Add-In Manager dialog box appears, as shown in Figure 30.11.

    The Add-in Manager dialog box.

    Figure 30.11. The Add-in Manager dialog box.

  9. Click the Add New button to launch the Open dialog box. Here, you can browse for your add-in.

  10. Locate the add-in that you want to add and click OK. The add-in you select is added to the Add-In Manager dialog box and is selected for you.

  11. Click Close. You now are ready to use the add-in.

Table 30.2. The structure of the USysRegInfo table.

Field NameDescription
SubKeyName of the subkey value in the Registry where the value you are adding is located.
TypeType of subkey value you are creating (String, Binary, or DWORD).
ValNameValue name for the entry.
ValueValue associated with the value name.

Using Wizards

A wizard consists of a series of dialog boxes; it provides a step-by-step interface to creating a database object. The wizard shields users from the complexities of the process. You probably are familiar with wizards such as the Form Wizard, the Report Wizard, and the Database Wizard. Access 97 supports the development of several types of custom wizards:

  • Table wizards

  • Query wizards

  • Form wizards

  • Report wizards

  • Property wizards

  • Control wizards

Looking At Design Guidelines

Wizard design guidelines are almost identical to builder design guidelines. The main difference is that wizards generally present the user with multiple modal dialog boxes, whereas a builder generally consists of a single modal dialog box. All the data requirements for the wizard must be met before the user can close the last dialog box.

Creating a Wizard

Creating a wizard is more complex than creating a builder. Creating a wizard generally involves a multi-page form and is usually responsible for creating database objects. Consider a wizard that creates a simple form. The wizard consists of two modal dialog boxes, shown in Figures 30.12 and 30.13. The first dialog box asks the user for a form caption, form name, and message to appear on the new form. The second dialog box enables the user to add OK and Cancel buttons to the form. The multi-page form and all the code that enables it to work are in the CHAP30LIB.MDA database on the accompanying CD-ROM.

Step 1 of the custom Form Wizard.

Figure 30.12. Step 1 of the custom Form Wizard.

Step 2 of the custom Form Wizard.

Figure 30.13. Step 2 of the custom Form Wizard.

Each page of the wizard contains code to ensure that it operates successfully. The form is called frmGetFormInfo. The first page of this multi-page form gives the user the opportunity to choose Cancel, Next, or Finish. The code for the Cancel button looks like this:

Private Sub cmdCancel1_Click()
   DoCmd.Close
End Sub

This code closes the wizard form. No other actions are taken, because the process is being canceled. If the user clicks Next, this code executes:

Private Sub cmdNext1_Click()
   DoCmd.GoToPage 2
   Me.Caption = "My Form Wizard - Step 2"
End Sub

This code moves to the second page of the form and changes the caption of the form to indicate that the user is on step 2 of the wizard. The code under the Finish button looks like this:

Private Sub cmdFinish1_Click()
   If CreateCustomForm() Then
      MsgBox "Form Created Successfully"
      DoCmd.Close
   Else
      MsgBox "Unable to Create Form"
   End IfEnd Sub

This code calls a function called CreateCustomForm, which is responsible for building the actual form. The details of the CreateCustomForm function are discussed later in this section. If the function returns True, the wizard form is closed and a message is displayed indicating that the process was successful. Otherwise, a message is displayed indicating that the form was not created successfully, and the user remains in the wizard. The second page of the form contains similar subroutines. The code under the Back button looks like this:

Private Sub cmdBack2_Click()
   DoCmd.GoToPage 1
   Me.Caption = "My Form Wizard - Step 1"End Sub

This code moves back to the first page of the form. If the user chooses Cancel, this code executes:

Private Sub cmdCancel2_Click()
   DoCmd.CloseEnd Sub

This code closes the form, taking no further action. If the user clicks Finish, the Click event code of the cmdFinish2 command button executes:

Private Sub cmdFinish2_Click()
   Call cmdFinish1_ClickEnd Sub

This code calls the code under the Click event of the cmdFinish1 command button.

The CreateCustomForm function, as seen in Listing 30.3, contains the code that actually builds the new form.

Example 30.3. The CreateCustomForm function builds the form.

Function CreateCustomForm() As Boolean

   On Error GoTo CreateCustomForm_Err

   Dim frmNew As Form
   Dim ctlNew As Control

   'Create a New Form and Set Several of Its Properties
   Set frmNew = CreateForm()
   frmNew.Caption = Forms!frmGetFormInfo.txtFormCaption
   frmNew.RecordSelectors = False
   frmNew.NavigationButtons = False
   frmNew.AutoCenter = True

   'Create a Label Control on the New Form
   'Set Several of Its Properties
   Set ctlNew = CreateControl(frmNew.Name, acLabel)
   ctlNew.Caption = Forms!frmGetFormInfo.txtLabelCaption
   ctlNew.Width = 3000
   ctlNew.Height = 1000
   ctlNew.Top = 1000
   ctlNew.Left = 1000

   'Evaluate to See if the User Requested an OK Command Button
   'If They Did, Add the Command Button and Set Its Properties
   'Add Click Event Code for the Command Button
   If Forms!frmGetButtons.chkOK.Value = –1 Then
      Set ctlNew = CreateControl(frmNew.Name, acCommandButton)
      ctlNew.Caption = "OK"
      ctlNew.Width = 1000
      ctlNew.Height = 500
      ctlNew.Top = 1000
      ctlNew.Left = 5000
      ctlNew.Name = "cmdOK"
      ctlNew.Properties("OnClick") = "[Event Procedure]"
      frmNew.Module.InsertText "Sub cmdOK_Click()" & vbCrLf & _
         vbTab & "DoCmd.Close acForm, """ & _
         Forms!frmGetFormInfo.txtFormName & _
         """" & vbCrLf & "End Sub"
   End If

   'Evaluate to See if the User Requested a Cancel Command Button
   'If They Did, Add the Command Button and Set Its Properties
   'Add Click Event Code for the Command Button
   If Forms!frmGetButtons.chkCancel.Value = –1 Then
      Set ctlNew = CreateControl(frmNew.Name, acCommandButton)
      ctlNew.Caption = "Cancel"
      ctlNew.Width = 1000
      ctlNew.Height = 500
      ctlNew.Top = 2000
      ctlNew.Left = 5000
      ctlNew.Name = "cmdCancel"
      ctlNew.Properties("OnClick") = "[Event Procedure]"
      frmNew.Module.InsertText "Sub cmdCancel_Click()" & vbCrLf & _
         vbTab & "MsgBox(""You Canceled!!"")" & vbCrLf & "End Sub"
   End If
   'If the User Entered a Form Name, Save the Form
   If Not IsNull(Forms!frmGetFormInfo.txtFormName) Then
      DoCmd.Save , Forms!frmGetFormInfo.txtFormName
   End If

   'Return True If No Errors
   CreateCustomForm = True
   Exit Function

CreateCustomForm_Err:
   MsgBox "Error # " & Err.Number & ": " & Err.Description
   CreateCustomForm = False
   Exit Function
End Function

The code begins by creating both form and control object variables. The form object variable is set to the return value from the CreateForm function. The CreateForm function creates a new form object. Several properties of the new form object are set: Caption, RecordSelectors, NavigationButtons, and AutoCenter. Next, the function uses the CreateControl function to create a new label. A reference to the new label is called ctlNew. The Caption, Width, Height, Top, and Left properties of the new label are set. If the user indicated that he or she wanted an OK button, a new command button is created. The Caption, Width, Height, Top, Left, Name, and Properties properties are all set. The InsertText method is used to insert code for the Click event of the command button. If the user requested a Cancel button, the same properties are set. Finally, if the user indicated a name for the new form, the Save method is used to save the new form object.

Note

Several functions exist to create and delete forms, reports, form controls, and report controls. You can use DAO code to create, modify, and delete tables and queries. Using the functions and DAO code, you can manipulate database objects any way you want.

Getting the Wizard Ready to Go

Like a builder, a wizard needs to be added to the Windows Registry before it can be used. You can do this by modifying the Registry directly or by adding entries to the USysRegInfo table. Figure 30.14 shows the completed Registry entry for the custom Form Wizard.

Registry entries for the custom Form Wizard.

Figure 30.14. Registry entries for the custom Form Wizard.

Notice that the function name is MyCustomForm. This is the entry point to the wizard. The Library key designates the name of the library add-in database containing the entry point function. The Description key specifies what appears in the New Object dialog box. Finally, the Index key designates the order in which the wizard is displayed in the list in the New Object dialog box. The MyCustomForm function simply calls the frmGetFormInfo form, initiating the wizard process:

Function MyCustomForm(strRecordSource As String) As Variant
   DoCmd.OpenForm FormName:="frmGetFormInfo", WindowMode:=acDialog
End Function

Using Menu Add-Ins

A menu add-in is a general-purpose tool that enables you to perform a task that generally affects multiple objects or Access itself. The Database Splitter and Database Documenter are examples of menu add-ins. You access menu add-ins through the Add-Ins submenu of the Tools menu.

Looking At Design Guidelines

Menu add-ins are available to the user whenever the Tools menu is available. Menu add-ins are not context-sensitive like wizards and builders. Therefore, they should in no way rely on what the user is doing at a particular moment.

Creating a Menu Add-In

Creating a menu add-in is just like creating a wizard. The difference is in how you install the add-in. The menu add-in must be registered under HKEY_LOCAL_MACHINESOFTWAREMicrosoftOffice8.0AccessMenu Add-Ins. You can accomplish the registration process by modifying the Registry directly or by using the USysRegInfo table. Figure 30.15 shows the Registry with the correct entries to run the Form Wizard created earlier in this chapter. Figure 30.16 shows how you can automate the registration process by using the USysRegInfo table. Three entries are included in the USysRegInfo table. All three entries designate the proper place in the Registry tree to add the new key. The first entry contains the subkey and a type of zero. The second entry contains the value name Expression and the name of the entry-point function as the value. Notice that the expression name is preceded by an equals (=) sign and is followed by parentheses. The quotation marks within the parentheses are required because this particular entry-point function requires an argument. The third and final entry contains the value name Library and the name of the library as the value. This is all you need to do to turn a wizard into a menu add-in.

Registry entries for the menu add-in.

Figure 30.15. Registry entries for the menu add-in.

The USysRegInfo entries for the menu add-in.

Figure 30.16. The USysRegInfo entries for the menu add-in.

Practical Examples: Designing Your Own Add-Ins

The types of builders, wizards, and menu add-ins that you create depend on your specific needs. To reinforce what you have learned, this section includes the step-by-step process for creating a builder to help you add validation text messages. When you invoke the builder, the Choose Builder dialog box shown in Figure 30.17 appears. This dialog box appears because you will design two builders: one that enables the user to select from a list of polite messages and another that enables the user to select from rude messages. If the user selects Polite Validation Text Builder, the dialog box in Figure 30.18 appears. If the user selects Rude Validation Text builder, the dialog box in Figure 30.19 appears.

The Choose Builder dialog box.

Figure 30.17. The Choose Builder dialog box.

The polite messages builder.

Figure 30.18. The polite messages builder.

The rude messages builder.

Figure 30.19. The rude messages builder.

The first entry-point function is located in basBuilders and is shown in Listing 30.4.

Example 30.4. The first entry-point function.

Function ValidTextPolite(strObject As String, _
            strControl As String, _
            strCurrentValue As String)

   On Error GoTo ValidTextPolite_Err
   DoCmd.OpenForm FormName:="frmPolite", _
                  WindowMode:=acDialog, _
                  OpenArgs:=strCurrentValue
   If SysCmd(acSysCmdGetObjectState, acForm, _
            "frmPolite") = acObjStateOpen Then
      Select Case Forms!frmPolite!optPolite.Value
         Case 1
            ValidTextPolite = "The Incorrect Value Was Entered"
         Case 2
            ValidTextPolite = "The Computer Cannot Comprehend Your Entry"
         Case 3
            ValidTextPolite = "I'm Sorry, Could You Please Try Again"
         Case 4
            ValidTextPolite = "Please Make Another Selection"
         Case 5
            ValidTextPolite = "Amount Too High"
         Case 6
            ValidTextPolite = "Amount Too Low"
      End Select
      DoCmd.Close acForm, "frmPolite"
   Else
      ValidTextPolite = strCurrentValue
   End If

ValidTextPolite_Exit:
   Exit Function

ValidTextPolite_Err:
   MsgBox "Error # " & Err.Number & ": " & Err.Description
   Resume ValidTextPolite_Exit
End Function

The ValidTextPolite function receives all the parameters required by a builder function. The function opens frmPolite modally, passing it the current validation text value of the selected control as the OpenArg. If the user selects a value from the frmPolite form and clicks OK, the value he or she selected is evaluated and the appropriate text is returned from the ValidTextPolite function. The return value is the value that becomes the validation text of the selected control. Listing 30.5 shows the Load event of frmPolite.

Example 30.5. The Load event of frmPolite.

Private Sub Form_Load()
   'Set the Value of the Option Group
   'To the Current Value of the Property
   Select Case Me.OpenArgs
         Case "The Incorrect Value Was Entered"
            Me!optPolite.Value = 1
         Case "The Computer Cannot Comprehend Your Entry"
            Me!optPolite.Value = 2
         Case "I'm Sorry, Could You Please Try Again"
            Me!optPolite.Value = 3
         Case "Please Make Another Selection"
            Me!optPolite.Value = 4
         Case "Amount Too High"
            Me!optPolite.Value = 5
         Case "Amount Too Low"
            Me!optPolite.Value = 6
      End Select

End Sub

This code ensures that the value of the option button on the frmPolite form reflects the text that currently is entered in the Validation Text property of the current control. The ValidTextRude entry-point function is similar to ValidTextPolite. Listing 30.6 shows the ValidTextRude entry-point text function; it is located in basBuilders.

Example 30.6. The ValidTextRude entry-point function.

Function ValidTextRude(strObject As String, _
            strControl As String, _
            strCurrentValue As String)

   On Error GoTo ValidTextRude_Err
   DoCmd.OpenForm FormName:="frmRude", _
                  WindowMode:=acDialog, _
                  OpenArgs:=strCurrentValue
   If SysCmd(acSysCmdGetObjectState, acForm, _
            "frmRude") = acObjStateOpen Then
      Select Case Forms!frmRude!optRude.Value
         Case 1
            ValidTextRude = "Get a Clue Dude"
         Case 2
            ValidTextRude = "What the Heck do You Think You're Doing?"
         Case 3
            ValidTextRude = "Give Me a Break!!"
         Case 4
            ValidTextRude = "I'm a Computer, I'm not an Idiot!!"
         Case 5
            ValidTextRude = "Read the Manual Dude"
         Case 6
            ValidTextRude = "You Really Think I Believe That?"
      End Select
      DoCmd.Close acForm, "frmRude"
   Else
      ValidTextRude = strCurrentValue
   End If

ValidTextRude_Exit:
   Exit Function

ValidTextRude_Err:
   MsgBox "Error # " & Err.Number & ": " & Err.Description
   Resume ValidTextRude_Exit
End Function

The Load event of frmRude is similar to the Load event of frmPolite, as Listing 30.7 shows.

Example 30.7. The Load event of frmRude.

Private Sub Form_Load()
   'Set the Value of the Option Group
   'To the Current Value of the Property
   Select Case Me.OpenArgs
         Case "Get a Clue Dude!"
            Me!optRude.Value = 1
         Case "What the Heck Do You Think You're Doing"
            Me!optRude.Value = 2
         Case "Give Me a Break!!"
            Me!optRude.Value = 3
         Case "I'm a Computer, I'm not an Idiot!!"
            Me!optRude.Value = 4
         Case "Read the Manual Dude"
            Me!optRude.Value = 5
         Case "You Really Think I Believe That?"
            Me!optRude.Value = 6
      End Select

End Sub

To create the builder, design both forms so that they look like the ones in Figures 30.18 and 30.19. Include code for the Load event of each form as listed previously. The code behind the OK button of each form sets the Visible property of the form to False. The code behind the Cancel button on each form closes the form. Make sure that you name the option groups optPolite and optRude so that the code runs properly for each form. You can place the two entry-point functions, ValidTextPolite and ValidTextRude, in any code module in the library database. The last step involves registering the two builders. The entries in USysRegInfo, shown in Figure 30.20, accomplish the task of registering the builder the first time that the add-in is selected through the Add-Ins dialog box. This table is located in CHAP30LIB.MDA.

Registry entries for the polite and rude builders.

Figure 30.20. Registry entries for the polite and rude builders.

Summary

By creating builders, wizards, and add-ins, you can enhance the development environment for yourself and your users. You even can add wizards so that your users can build their own queries, forms, or reports on-the-fly without a full copy of Access. Your wizard simply needs to prompt the user for the appropriate information and then build the objects to your specifications. What you can do with wizards, builders, and add-ins is limited only by your imagination.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.172.249