• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Can someone help me with this code?

I have a form that I use the filter by form command with, and when the filter is applied and it doesn't find any records to be filtered, it gives me a message for Run time error 3021. Then it asks me if I want to debug or end, you know....

Well here is the code.

Private Sub Form_Current()
   
    If Me.NewRecord Then
       Me.RecordsetClone.MoveLast
       Nav2 = Me.RecordsetClone.AbsolutePosition + 1
    Else
        Me.RecordsetClone.Bookmark = Me.Bookmark
        Nav = Me.RecordsetClone.AbsolutePosition + 1
    End If
   
    If Me.CurrentRecord Then
        Me.RecordsetClone.MoveLast
        Nav2 = Me.RecordsetClone.AbsolutePosition + 1
    Else
        Me.RecordsetClone.Bookmark = Me.Bookmark
        Nav = Me.RecordsetClone.AbsolutePosition + 1
    End If
   
    If Me.FilterOn = True Then
        Me.Label148.Visible = True
    Else
        Me.Label148.Visible = False
    End If
   
End Sub


Is their any way I can code in a message box to pop up if their is no records that match the filter.
0
Mtlca401
Asked:
Mtlca401
1 Solution
 
dds110Commented:
Private Sub Form_Current()
On Error GoTo Err_Form_Current:  
   If Me.NewRecord Then
      Me.RecordsetClone.MoveLast
      Nav2 = Me.RecordsetClone.AbsolutePosition + 1
   Else
       Me.RecordsetClone.Bookmark = Me.Bookmark
       Nav = Me.RecordsetClone.AbsolutePosition + 1
   End If
   
   If Me.CurrentRecord Then
       Me.RecordsetClone.MoveLast
       Nav2 = Me.RecordsetClone.AbsolutePosition + 1
   Else
       Me.RecordsetClone.Bookmark = Me.Bookmark
       Nav = Me.RecordsetClone.AbsolutePosition + 1
   End If
   
   If Me.FilterOn = True Then
       Me.Label148.Visible = True
   Else
       Me.Label148.Visible = False
   End If
   
Exit_Form_Current:
    Exit Sub

Err_Form_Current:
If Err.Number = 3021 Then
'There was no record found
    MsgBox "No Record Found"
    Resume Exit_Form_Current:
Else
    MsgBox Err.Description,,Err.Number
    Resume Exit_Form_Current:
End If

End Sub


HTH
0
 
Mtlca401Author Commented:
Thank you for the answer, even though I figured it out I'll still accept your answer so you can get points for it!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now