textbox for gradual filtering

R

RGBrighton

Hi,
I have a simple, continous form based on a single table.
The records are displayed by order of 'modulecode' - a string of about 5
characters.
I have placed an unbound textbox (txtModuleCodeFilter) in the form header
which I hope to use to type in a couple of characters and have the form
filter to modulecodes starting with those characters.

The code below works fine.
The problem is that after a single keystroke in the textbox the filter
changes but then the whole text in the textbox is highlighted; so the next
keystroke overwrites the previous one!
I need to filter to 2 or 3 characters but to do this I have to keep clicking
the cursor to the end of the textbox before typing the next character.
How can I arrange this so that the user can just type a few characters in
the textbox and have the filter respond immediately to each successive
keystroke?

I hope to avoid the 2-stage: 'Type in the box then click button for filter'
approach.

Here is the code:

Private Sub txtModuleCodeFilter_Change()
Dim L As Integer
Dim CodeSelected As String

CodeSelected = Nz(txtModuleCodeFilter.Text)
'Filter the form to start like the textbox
If CodeSelected = "" Then
Me.FilterOn = False
Else
L = Len(CodeSelected)
Me.Filter = "left(ModuleCode, " & L & ") = '" & CodeSelected & "'"
Me.FilterOn = True
End If
End Sub

Any suggestions gratefully received.

Thanks
Richard
 
J

June7 via AccessMonster.com

Try AfterUpdate event for txtModuleCodeFilter instead of the Change event.
Also, your Nz() function does not have argument for alternate value. Should
be Nz(txtModuleCodeFilter.Text,"").
 
M

Mr. B

RGBrighton,

Usinig the On Change event is the correct event, however, try code like the
following:

Dim strFilterVal As String
If Me.txtModuleCodeFilter.Text > "" Then
strFilterVal = Me.txtModuleCodeFilter.Text
Me.Filter = "Name Like '" & strFilterVal & "*'"
Me.FilterOn = True
Me.txtModuleCodeFilter.SelStart = Len(Me.NameOfFilterControl.Text)
Me.txtModuleCodeFilter.SelLength = 0
Else
Me.FilterOn = False
End If

-----
HTH
Mr. B
http://www.askdoctoraccess.com/
Doctor Access Downloads Page:
http://www.askdoctoraccess.com/DownloadPage.htm
 

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