Adding an Alpha Search Button on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know how to add Alpha search button on a form? For example, I
have a list of 600 names in my table, what I want on the top of my form is
alphabets A-Z and when someone clicks on any letter, all the names starting
with that letter show up. Can anyone help me? Thank you for your time.
 
I maanged to do this by using an option group with A-Z and an All button as
well and use the code below to restrict the list to the relevant names:

Dim strSearchChr

Select Case SearchOption

Case 1
strSearchChr = "A"
Case 2
strSearchChr = "B"
Case 3
strSearchChr = "C"
Case 4
strSearchChr = "D"
Case 5
strSearchChr = "E"
Case 6
strSearchChr = "F"
Case 7
strSearchChr = "G"
Case 8
strSearchChr = "H"
Case 9
strSearchChr = "I"
Case 10
strSearchChr = "J"
Case 11
strSearchChr = "K"
Case 12
strSearchChr = "L"
Case 13
strSearchChr = "M"
Case 14
strSearchChr = "N"
Case 15
strSearchChr = "O"
Case 16
strSearchChr = "P"
Case 17
strSearchChr = "Q"
Case 18
strSearchChr = "R"
Case 19
strSearchChr = "S"
Case 20
strSearchChr = "T"
Case 21
strSearchChr = "U"
Case 22
strSearchChr = "V"
Case 23
strSearchChr = "W"
Case 24
strSearchChr = "X"
Case 25
strSearchChr = "Y"
Case 26
strSearchChr = "Z"

End Select

If strSearchChr = 0 Then
Me.FilterOn = False
Else
Me.Filter = "[Name] LIKE '" & strSearchChr & "*'"
Me.FilterOn = True
End If
 
Simon Maystre said:
I maanged to do this by using an option group with A-Z and an All button as
well and use the code below to restrict the list to the relevant names:

How about

strSearchChr = Chr(64 + SearchOption)

Tom Lake
 
I can see what you want to do, but might I suggest an alternative, to have
a combo box and 'Filer button'. Do the same as is suggested above, but
with the values being in a combo box instead.

Doing it this way will reduce the number of controls from 28 controls (26
option buttons, 1 frame and 1 All option) down to just 2 controls. There
are two real benefits here:

1. Less space taken up on your form (nobody likes to see hundreds of
controls on any form)

2. Takes up less memory - each control takes up a small amount of memory,
and therefore affects the speed in which your form loads.

whilst I know this is not the solution you wanted, it is what I would do,
and have in the past.

Cheers

John Webb
 
Mojo
Take a look in the Customer Phone List in the northwind sample database
there is a nice solution too

Herman
 
Back
Top