evalesthy:
Thanks very much for the recommendation, it's very much appreciated. You cheered me up so much that I thought I'd take the time to demonstrate how with a few lines of code Wayne can get his Form up and running combining both FancyPrairie's and Carol57's Methods.
Wayne:
On your Form, create 28 Buttons, name 26 of them "A-Z" respectively, one of them "0-9" and the last one "All".
Paste this code into the Form's Module:
Private Function FilterMyForm()
Dim strFilter
strFilter = Screen.ActiveControl.Name
Me.Filter = "CompanyName Like '[" & strFilter & "]*'"
Me.FilterOn = True
Me!txtCustomFilter = vbNullString
End Function
Private Sub All_GotFocus()
DoCmd.ShowAllRecords
End Sub
Change
CompanyName to the Field that you want to use for your Filter.
Compile and Save the Module. Close the Visual Basic Editor.
In the Form's Design View, aelect all your Buttons other than "All".
In the Properties Window scroll down until you see "On Got Focus", Type In:
=FilterMyForm()
This will save you having to do it 27 times.
Click on the Button "All", "[Event Procedure]" should appear in the "On Got Focus" Text Box, if not select it from the list. That's it.
An additional feature I like to give people is a Custom Filter, which will display all instances of a String typed into a Text Box, to do this:
Add a Text Box to your Form, call it "txtCustomFilter". Add this to the Form's Module:
Private Sub txtCustomFilter_AfterUpdate()
Me.Filter = "CompanyName Like '*" & Me!txtCustomFilter & "*'"
Me.FilterOn = True
Me!CompanyName.SetFocus
End Sub
Once again change
CompanyName to your Field Name.
Compile and Save the Module. Close the Visual Basic Editor.
Check the AfterUpdate of the Text Box, should say "[Event Procedure]", if not select it from the list.
Finally, I don't want to get too Technical, naming Controls A, B, C etc doesn't Conform to Usual Naming Conventions, i.e. Button A should really be comA or similar to identify it as a Command Button if used in your Code. I don't want to give you bad habits. The alternatives here are to use either the "Caption" or "Tag" Properties of the Buttons. As long as they say A, B, C etc the Code above will work just the same. If you used the Tag Property you would change the line(s) in the above Code containing "Screen.ActiveControl.Name":
From:
Screen.ActiveControl.Name
To:
Screen.ActiveControl.Tag
Finally, I haven't included any Error Procedures, I'll leave that to your own discretion.
I've posted the DB I wrote this in at
you are welcome to Download it to see how it's done. The File is called "FilterForm.zip"
Have a Good Weekend All
Bill