coding filter on click

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

Guest

I have a table with 2 fields--Diagnosis and Code. I want to have a form that filters this table after a few letters are placed in a text box at the top of the form.

So the user types the first few letters of diagnosis.....presses command button...the letters typed are used to filter table and return all diagnoses (with their linked codes) that begin with the letters typed.

Should I use a subform for this? Should it be based on the table or some query of the table?

Any help appreciated...
 
No need for a subform.

1. Place an unbound text box on the form, for the user to enter the text to
find. Typically the text box might go in the Form Header section (View
menu). In the example below, this text box is named "txtFindDiag".

2. In the AfterUpdate event procedure of the text box, create the filter
string, and assign it to the form. The example assumes a Text field named
"Diagnosis":

Private Sub txtFindDiag_AfterUpdate()
With Me.txtFindDiag
If IsNull(.Value) Then
'Nothing entered: show all records
Me.FilterOn = False
Else
Me.Filter = "[Diagnosis] Like """ & .Value & "*"""
Me.FilterOn = True
End If
End With
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Ron said:
I have a table with 2 fields--Diagnosis and Code. I want to have a form
that filters this table after a few letters are placed in a text box at the
top of the form.
So the user types the first few letters of diagnosis.....presses command
button...the letters typed are used to filter table and return all diagnoses
(with their linked codes) that begin with the letters typed.
 
Back
Top