Access Cookbook - Ken Getz [169]
Table 8-4. The fields in qryPersonComboBox
Query field
Sort
Criteria
PersonId
(None)
(None)
FullName: [LastName] & ", " & [FirstName]
(None)
(None)
LastName
Ascending
Like [Forms]![frmPersonPopup2]![txtChar] & "*"
FirstName
Ascending
(None)
Reopen the pop-up form created in Steps 2 and 3. Set the Enabled property of the combo box to No. Set the RowSource property to point to the query created in Step 4. In the sample database, we set the properties of the cboPersonId combo box to the values in Table 8-5.
Table 8-5. Property settings for cboPersonId
Property
Setting
Enabled
No
RowSourceType
Table/Query
RowSource
(Blank)
ColumnCount
2
ColumnHeads
No
ColumnWidths
0";2.5"
BoundColumn
1
ListRows
8
ListWidth
2.5"
Create a new event procedure for the text box's Change event. (If you're unsure of how to do this, see How Do I Create an Event Procedure? in the Preface of this book.) Add the following code to the event procedure:
Private Sub txtChar_Change( )
If Not IsNull(Me.txtChar.Text) Then
Me.cboPersonID.Enabled = True
Else
Me.cboPersonID.Enabled = False
End If
End Sub
Change txtChar to the name of your text box and cboPersonId to the name of your combo box.
Create a new event procedure for the text box's AfterUpdate event and add the following code to it:
Private Sub txtChar_AfterUpdate( )
Dim ctlPersonId As ComboBox
Dim ctlChar As TextBox
Set ctlPersonId = Me.cboPersonID
Set ctlChar = Me.txtChar
If Not IsNull(ctlChar) Then
ctlPersonId.RowSource = "qryPersonComboBox"
ctlPersonId.SetFocus
ctlPersonId.Dropdown
End If
End Sub
Change txtChar to the name of your text box, and cboPersonId to the name of your combo box. Change qryPersonComboBox to the name of the query you created in Step 4.
Create the following new event procedure for the OK command button's Click event:
Private Sub cmdOK_Click( )
Me.Visible = False
End Sub
Create the following new event procedure for the Cancel command button's Click event:
Private Sub cmdCancel_Click( )
DoCmd.Close acForm, Me.Name
End Sub
Save the pop-up form and close it.
Reopen the form from Step 1 in design view. Add a button called cmdPopup to the right of the text box. Add the following event procedure to cmdPopup's Click event:
Private Sub cmdPopup_Click( )
Const acbcPopup = "frmPersonPopup"
' Open up pop-up form in dialog mode.
DoCmd.OpenForm acbcPopup, WindowMode:=acDialog
' Check if form is still loaded.
' If yes, then OK button was used to close pop-up.
If SysCmd(acSysCmdGetObjectState, acForm, acbcPopup) <> 0 Then
Me.PersonID = Forms(acbcPopup)!cboPersonID
DoCmd.Close acForm, acbcPopup
End If
End Sub
Change frmPersonPopup to match the name of the pop-up form. Change PersonId and cboPersonId to the names of the appropriate controls.
Discussion
When you have a form that loads and executes slowly, you need to analyze the form and weigh the advantages and disadvantages of using graphic features. After a careful analysis of the frmCategoriesOriginal form in the 08-02a.MDB database, we made several changes.
First, we changed the unbound object frame control to an image control. The OLE-based object frame control can be used to hold graphic images, sound, and other OLE-based data such as Excel spreadsheets or Word documents. But if you need to display only an unbound bitmap, you're better off using the more resource-conservative image control.
Second, we removed the form watermark, as this feature slows down form execution slightly. The improvement in performance depends on the color-depth of the removed image and the speed of your machine.
Finally, we created a second page and moved the text box bound to the memo field and the bound object frame bound to the OLE field to this second page. These field types (memo and OLE)