Disabling Buttons if No Records Are Displayed

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

Else

Me!cmdDetail.Enabled = True Me!cmdCityBusinesses.Enabled Me!cmdCopy.Enabled = True

End If

Exit_Procedure:

On Error Resume Next Exit Sub

Error_Handler:

MsgBox Err.Number & ": " & Err.Description

Resume Exit_Procedure

Resume

End Sub

The next section explains how to enhance forms with cascading combo boxes.

0 0

Post a comment