Display Message if Filter Reurn no results

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

I have a button on a form that filters records based upon
a value in a text box. This works fine. I was even able
to write a a function (DisplayMessage) that displays a
message is the text box is left blank.

However, here is what I am wondering.....
What if the filter has no results? The form displays with
zero records, ready to type in a new one. I would rather
display a message that says something like "Your Filter
Has no Matches"

I know reports have the OnNoData event, is there anything
I can do here on a form? The form stays open when this
button is pressed.... I was thinking there has to be some
RecordCount Property.... perhaps I can use the OnFilter
event...

Here is what I have... thanks in advance for any input.

Don

Private Sub Command70_Click()

If IsNull([txtViewUnresolved]) = True Then
DisplayMessage ("Message")
Else
Me.Filter = "AssignedTo='" & txtViewUnresolved
& "' AND Status <> 'Resolved'"
Me.FilterOn = True
End If

End Sub
 
Hi Don

Yes, you can use the RecordCount property:

Me.Filter = "..."
Me.FilterOn = True
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Filter returns no records"
Me.FilterOn = False
End If
 
This seems to Work too....

If Me.Recordset.RecordCount = 0 Then
DisplayMessage ("No Records were found")
DoCmd.ShowAllRecords
End If

Any Advantage of one over the other?

Thanks
-----Original Message-----
Hi Don

Yes, you can use the RecordCount property:

Me.Filter = "..."
Me.FilterOn = True
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Filter returns no records"
Me.FilterOn = False
End If

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Don said:
I have a button on a form that filters records based upon
a value in a text box. This works fine. I was even able
to write a a function (DisplayMessage) that displays a
message is the text box is left blank.

However, here is what I am wondering.....
What if the filter has no results? The form displays with
zero records, ready to type in a new one. I would rather
display a message that says something like "Your Filter
Has no Matches"

I know reports have the OnNoData event, is there anything
I can do here on a form? The form stays open when this
button is pressed.... I was thinking there has to be some
RecordCount Property.... perhaps I can use the OnFilter
event...

Here is what I have... thanks in advance for any input.

Don

Private Sub Command70_Click()

If IsNull([txtViewUnresolved]) = True Then
DisplayMessage ("Message")
Else
Me.Filter = "AssignedTo='" & txtViewUnresolved
& "' AND Status <> 'Resolved'"
Me.FilterOn = True
End If

End Sub


.
 
I think that DoCmd.ShowAllRecords just does a FilterOn = False "under the
hood". I believe it's only there for macros and backward compatibility.
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Don said:
This seems to Work too....

If Me.Recordset.RecordCount = 0 Then
DisplayMessage ("No Records were found")
DoCmd.ShowAllRecords
End If

Any Advantage of one over the other?

Thanks
-----Original Message-----
Hi Don

Yes, you can use the RecordCount property:

Me.Filter = "..."
Me.FilterOn = True
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Filter returns no records"
Me.FilterOn = False
End If

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Don said:
I have a button on a form that filters records based upon
a value in a text box. This works fine. I was even able
to write a a function (DisplayMessage) that displays a
message is the text box is left blank.

However, here is what I am wondering.....
What if the filter has no results? The form displays with
zero records, ready to type in a new one. I would rather
display a message that says something like "Your Filter
Has no Matches"

I know reports have the OnNoData event, is there anything
I can do here on a form? The form stays open when this
button is pressed.... I was thinking there has to be some
RecordCount Property.... perhaps I can use the OnFilter
event...

Here is what I have... thanks in advance for any input.

Don

Private Sub Command70_Click()

If IsNull([txtViewUnresolved]) = True Then
DisplayMessage ("Message")
Else
Me.Filter = "AssignedTo='" & txtViewUnresolved
& "' AND Status <> 'Resolved'"
Me.FilterOn = True
End If

End Sub


.
 
Back
Top