how do I make a customer search like northwind?

D

Duane Hookom

You can replace all the buttons and macro with a single, wide command button
and a little code.
1) Create a continuous form for the customers table and
display the form header and footer sections.
2) Turn off the tool box wizard and add a command button
to the footer section making it about as wide as the form
3) Set the font to fairly large and set the caption to "All"
4) Name the command button "cmdIndex" and set its
mouse move event to:

Private Sub cmdIndex_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Dim strChar As String
strChar = Chr(65 + Int((X / Me.cmdIndex.Width) * 27))
If strChar = "[" Then
strChar = "All"
End If
Me.cmdIndex.Caption = strChar
End Sub

5) compile the code and view the form in form view while
moving your mouse from left to right over the button
The caption should change from "A" to "Z" to "All"
6) Go back to the code window and set the On Click
event of cmdIndex to:

Private Sub cmdIndex_Click()
If Me.cmdIndex.Caption <> "All" Then
Me.Filter = "Left([CompanyName],1) ='" & _
Me.cmdIndex.Caption & "'"
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub

7) Compile and save the form.

The single command button should now allow you to filter the form records.
 

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