Filter Form Records button

  • Thread starter Thread starter jakeatkins
  • Start date Start date
J

jakeatkins

I'm working with a form that displays all records, but has a filter button to
show only a certain year, or all (*). Once prompted for the year in the
messagebox, hitting cancel returns me to the form but with NO records showing.
How can I hit cancel and have it go back to the form, displaying whatever
records it was before hitting the filter button? Here's my current button
code:
------------------------------------------------------------------------------

Private Sub btnFindStyle_Click()
On Error GoTo Err_btnFindStyle_Click
Dim msg, Style, Title, myResponse

msg = "Enter Year (YYYY) to Show, or * to show all:"
Title = "Enter Year"
myResponse = InputBox(msg, Title, "2007")
DoCmd.ApplyFilter , "Year Like '" & myResponse & "'"

Exit_btnFindStyle_Click:
Exit Sub

Err_btnFindStyle_Click:
MsgBox Err.Description
Resume Exit_btnFindStyle_Click

End Sub
 
jakeatkins said:
I'm working with a form that displays all records, but has a filter button to
show only a certain year, or all (*). Once prompted for the year in the
messagebox, hitting cancel returns me to the form but with NO records showing.
How can I hit cancel and have it go back to the form, displaying whatever
records it was before hitting the filter button? Here's my current button
code:
------------------------------------------------------------------------------

Private Sub btnFindStyle_Click()
On Error GoTo Err_btnFindStyle_Click
Dim msg, Style, Title, myResponse

msg = "Enter Year (YYYY) to Show, or * to show all:"
Title = "Enter Year"
myResponse = InputBox(msg, Title, "2007")
DoCmd.ApplyFilter , "Year Like '" & myResponse & "'"


Check myResponse for a zero length string:

If myResponse <> "" Then
DoCmd.ApplyFilter . . .
End If
 
Thanks, a simple fix!!

Marshall said:
I'm working with a form that displays all records, but has a filter button to
show only a certain year, or all (*). Once prompted for the year in the
[quoted text clipped - 12 lines]
myResponse = InputBox(msg, Title, "2007")
DoCmd.ApplyFilter , "Year Like '" & myResponse & "'"

Check myResponse for a zero length string:

If myResponse <> "" Then
DoCmd.ApplyFilter . . .
End If
 
Back
Top