Filter Form Records button

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
 
M

Marshall Barton

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
 
J

jakeatkins via AccessMonster.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top