When you give your users the capability to narrow a list of records, they might figure out a way to omit all of them! The subroutine EnableDisableControls is called just in case no records meet the criteria. Otherwise, users would get an error if they clicked the Detail button because there wouldn't be a key with which to open the detail record. To prevent that, the Detail button is disabled, as shown in Figure 15-5.
The code to disable or enable the appropriate buttons looks like this:
Public Sub EnableDisableControls() On Error GoTo Error_Handler
If Me.RecordsetClone.RecordCount Me!cmdDetail.Enabled = False Me!cmdCityBusinesses.Enabled Me!cmdCopy.Enabled = False
Me!cmdDetail.Enabled = True Me!cmdCityBusinesses.Enabled Me!cmdCopy.Enabled = True
On Error Resume Next Exit Sub
MsgBox Err.Number & ": " & Err.Description
The next section explains how to enhance forms with cascading combo boxes.
Was this article helpful?