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, the design should be consistent with that of the builders included in 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 scrollbars.
- 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:
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 you launch the builder. The function launches the builder form and then returns a value to the appropriate property. Listing 25.1 is an example of a builder function. It is located in CHAP25LIB.MDA in the basBuilders module on the accompanying CD-ROM. |
Listing 25.1 Creating a Builder Function
Function SpecialEffect(strObject As String, _
strControl As String, _
strCurrentValue As String)
On Error GoTo SpecialEffect_Err
'Open the special effect form, passing it the special
'effect currently selected
DoCmd.OpenForm FormName:="frmSpecialEffect", _
WindowMode:=acDialog, _
OpenArgs:=strCurrentValue
'If the user selects a special effect and clicks OK, the
'form remains open but hidden. Return a value based on
'which special effect the user selected
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
'Close the form when done
DoCmd.Close acForm, "frmSpecialEffect"
Else
'If the user clicks cancel, return the original value
'for the special effect
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 operates - strControl
The name of the control to which the property applies - strCurrentValue
The current property value
Although the names of the arguments are arbitrary, you cannot change their data types, positions, and content. Access automatically fills in the values for the three arguments.The SpecialEffect function opens the form called frmSpecialEffect in Dialog mode, passing it the current value of the property as the OpenArgs value. Figure 25.1 shows the frmSpecialEffect form.
Figure 25.1. Here we see 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 within 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 is still open, the function can determine which option button the user selected.The Case statement within the SpecialEffect function evaluates the value of the optSpecialEffect option group 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 selects the second option button (with a value of 2), for example, the SpecialEffect function returns the string "Raised". After the code evaluates the option button value and sets the return value, the code no longer needs the frmSpecialEffect form, so the code then closes the form.If the user chooses Cancel from the frmSpecialEffect form, the SysCmd function returns False, and the code sets the return value of the SpecialEffect function equal to strCurrentValue, the original property value. In this case, the code does not change the property value.
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 you set the SpecialEffect property from the Property window, no wizard exists to assist with the process. Although the process of setting the SpecialEffect property is quite simple, the main problem is that it is difficult to remember exactly what each special effect looks like. I designed the custom special effect builder 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. I have set the Modal property of the form to Yes. I removed the record selectors, navigation buttons, and scrollbars. I set the AutoCenter property of the form to True. I included six text boxes on the form. I set the special effect of each text box to a different style. The form includes an option group. This group has a different value, depending on which option button the user selects. The code sets the Default property of the OK command button to Yes, making the OK button the default choice. The code sets the Cancel property of the Cancel command button to Yes, ensuring that if the user presses Esc, the code behind the Cancel button executes. The preceding section showed the code behind the Click events of the OK and Cancel buttons. Listing 25.2 shows one more piece of code that enhances this builder.
Listing 25.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
I added this subroutine to 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 SpecialEffect 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 in one of 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:
You must create four value names for the subkey. They are Can Edit, Description, Function, and Library. Table 25.1 describes these value names for the registry subkey.
Figure 25.2. Use the Registry Editor to invoke the Property Wizards Registry key.

Figure 25.3. Double-click the Can Edit value name to bring up the Edit DWORD Value dialog box.

Figure 25.4. The Edit String dialog box appears when you double-click the Description value name.

Figure 25.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 you successfully created all the registry entries, you can use the builder. To test the builder, open any database (other than 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 arrow, as shown in Figure 25.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 SpecialEffect property.
Figure 25.5. The completed registry entries required to add the builder.

Figure 25.6. Using the custom builder.

NOTEIf you do not exactly follow the format for the value names, the message There Is an Invalid Add-in Entry for 'SpecialEffectBuilder' appears, as shown in Figure 25.7. You must correct the registry entry.
Figure 25.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. You must call the table USysRegInfo. Follow these steps:
Figure 25.8. Here is the Tables tab with system objects visible.

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

Figure 25.10. The completed table with entries for registry.

Figure 25.11. The Add-in Manager dialog box.
