New to Acess, form filtering

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

I have a contact table that has about 400 records in it. I
would like to put a button for every letter of the
alphabet so when clicked the form would only display the
records of last names that correspond to that letter.

Please help me with the steps I need to make this happen.
Thanks,
 
Hi

Here is a code snippet from an actual application that does exactly what you
want.

The Tab Control is called Tabs and the SubForm is called Address Book Subform.

Use what you need.


Private Sub Tabs_AfterUpdate()
Dim objTabs As Object
Dim stLike As String

DoCmd.Hourglass True
Set objTabs = Me!Tabs.Object
Me![Address Book Subform].Form.Painting = False
If (objTabs.Value = 0) Then
Me![Address Book Subform].Form.RecordSource = "SELECT * FROM
Customers;"
Else
stLike = "'" & Chr$(64 + objTabs.Value) & "*'"
Me![Address Book Subform].Form.RecordSource = "SELECT * FROM Customers
WHERE [Company Name] LIKE " & stLike & ";"
End If
Me![Address Book Subform].Form.Painting = True
DoCmd.Hourglass False

Me![Address Book Subform].SetFocus
End Sub
 
Back
Top