Finding a record with a toggle button and filter

Copper Contributor

Just got a question regarding VBA in Access 2016. I want to create essentially a simple find option. I have a toggle button, and this code. I want the user to be able to hit the toggle button, be presented with a dialoge box, and search for whatever they enter. If they enter nothing, or they hit cancel, I want the toggle button to toggle off. If a filter is implemented, I want the user to be able to turn off the filter by toggling off the button.

Private Sub AlbumSearch_Click()
If AlbumSearch Then
Dim Search As String
Search = InputBox("Please Enter Album Name", "Album_Name")
If Search = "" Then Exit Sub
Me.Filter = "Album_Name LIKE """ & Search & """"
Me.FilterOn = True
Else
Me.Filter = ""
End If
Me.FilterOn = Me.AlbumSearch
End Sub

First of All, what I want, is that if the search is empty, before the program terminates, it will toggle off the find button. Also, If someone could explain the last part of the code, from the Else statement down. Thanks!

0 Replies