Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message for NO DATA found on a form filter 2

Status
Not open for further replies.

DomFino

IS-IT--Management
Jul 9, 2003
278
US
Hi Everyone,
I have a form that has several command buttons that when selected act as a filter. The problem I have is if there are no records for the select button I need a way to pop up a message saying No Records Found.

This is how the code looks behind each button:

Code:
Private Sub Labe11_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""ALD"""
End Sub

Private Sub Label2_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""AM*"""
End Sub

Private Sub Label3_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""DRR"""
End Sub

Private Sub Label4_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""GMK"""
End Sub

Private Sub Label5_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""JLE"""
End Sub

Private Sub Label6_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""MDL"""
End Sub

Private Sub Label7_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""*"""
End Sub

In reports there is a NO DATA option, however I have not found a similar option for a Form.

Any help will be greatly appreciated.
Thanks,
Dom
 
You can use, roughly:
Me.RecordsetClone.Recordcount = 0
 
Hi DomFino,
Is used, tnx to Remou, the following code for finding no records when applying a filter.
Code:
Private Sub FilterVoyage_AfterUpdate()
   Me.Filter = "VoyageID = " & FilterVoyage
   Me.FilterOn = True
   
   If Me.Recordset.RecordCount = 0 Then
    MsgBox "None of these"
    Me.Undo
   'SendKeys "{esc}", True
   Me.FilterOn = False
End If
End Sub

Pampers - [afro]

you're neven too young to learn
 
Remou and Pampers,
Thanks for the quick accurate reply. I used your suggested code and it works perfectly.

Final Code
Code:
Private Sub Labe11_Click()
    DoCmd.ApplyFilter "", "[o_recruit] Like ""ALD"""
    If Me.Recordset.RecordCount = 0 Then
       MsgBox "No Records To Display"
       Me.Undo
       Me.FilterOn = False
    End If
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top