Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources] - نسخه متنی

Alison Balter

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



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 25.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 25.18 appears. If the user selects Rude Validation Text Builder, the dialog box in Figure 25.19 appears.

Figure 25.17. The Choose Builder dialog box.


Figure 25.18. The polite messages builder.


Figure 25.19. The rude messages builder.


Listing 25.4 shows the first entry-point function, located in basBuilders.

Listing 25.4 The First Entry-Point Function

Function ValidTextPolite(strObject As String, _
strControl As String, _
strCurrentValue As String)
On Error GoTo ValidTextPolite_Err
'Open the Builder form
DoCmd.OpenForm FormName:="frmPolite", _
WindowMode:=acDialog, _
OpenArgs:=strCurrentValue
'If the user selected a message and clicked OK,
'return the selected text to the caller
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
'Close the form
DoCmd.Close acForm, "frmPolite"
'If the user clicked cancel, return the original value
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 shown in Listing 25.4 receives all the parameters required by a builder function. The function opens frmPolite modally, passing it the current ValidationText property value of the selected control as the OpenArg. If the user selects a value from the frmPolite form and clicks OK, the code evaluates the selected value, and returns the appropriate text from the ValidTextPolite function. The return value becomes the validation text of the selected control. Listing 25.5 shows the Load event of frmPolite.

Listing 25.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 the user entered in the ValidationText property of the current control. The ValidTextRude entry-point function is similar to ValidTextPolite. Listing 25.6 shows the ValidTextRude entry-point text function; you can find it in basBuilders.

Listing 25.6 The ValidTextRude Entry-Point Function

Function ValidTextRude(strObject As String, _
strControl As String, _
strCurrentValue As String)
On Error GoTo ValidTextRude_Err
'Open the Builder form
DoCmd.OpenForm FormName:="frmRude", _
WindowMode:=acDialog, _
OpenArgs:=strCurrentValue
'If the user selected a message and clicked OK,
'return the selected text to the caller
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
'Close the form
DoCmd.Close acForm, "frmRude"
'If the user clicked cancel, return the original value
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 25.7 shows.

Listing 25.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 25.18 and 25.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 25.20, accomplish the task of registering the builder the first time that the user selects the add-in through the Add-ins dialog box. You can find this table in the CHAP25LIB.MDA database.

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



/ 544