I have a search query that is displayed in a sub form that is in datasheet view.
When selecting a record from this subform, I need to have users click a button (for tracking purposes) to access the record’s data on other parts of the form. Currently, the Access Record Button is set to enabled = true when the query runs (via a submit button).
The problem with this is that if a search yields no results, the access record button is still click-able and tries to access a record that doesn’t exist; giving me: “Run-time error 2427: You entered an expression that has no value”
Is there a way to disable that button if the query returns no results or if no record is selected?
EDIT: Code for the button at this point.
Private Sub cmdSubmit_Click()
Me!SearchResults.Form.RecordSource = "qryPendingCriteriaCIP"
Me!SearchResults.Form.Requery
Me!SearchResults.Form.Visible = True
If Forms!frm_SearchMulti!SearchResults.Form.RecordCount > 0 Then
Me.cmdExport.Enabled = True
Me.SearchResults.Enabled = True
Me.cmdPass.Enabled = True
Else
Exit Sub
End If
End Sub
Is the button on the main form and do you mean you wish to check that there are records in the subform?
Or to check a row:
Or to check the query: