Want Search Textbox to filter form but keep focus & highlight

bignose2

Registered User.
Local time
Today, 02:23
Joined
May 2, 2010
Messages
251
This is driving me crazy,
over the years ended up having lots of different tricks to achieve this but always messy & all over the place. There must be a clean & proper way.

Basically I have a text box. I type a name & it filters the form.
For speed & ease I type the name, either press tab or enter. Don't want to have to reach for the mouse each time or have to let it tab to a button to press space or something.

I want it to stay on the search textbox and highlight, ready to over type.
I use me.filter usually in AfterUpdate but mostly OnExit letting it naturally tab to another control & then back again. This is always tricky as not lost focus yet can't easily move focus around.

Whole host of issues with this in either procedure.
AfterUpdate I would think is the obvious but you can never highlight.
Me!FindNames.SelStart = 0
Me!FindNames.SelLength = Len(FindNames.Text)
At it hits the end sub in the AfterUpdate I guess it is reset as this looses the highlighting & cursor is at the start of the textbox, you have to delete previous. I often want to keep what is types also so not auto delete.

I have looked at before update & cancel = true but this seems to bring up a whole different set of issues.

this is what I thought should work & be so simple but stepping through all highlighted OK but as soon as you F8 on End Sub if clears.

Private Sub FindNames_AfterUpdate()

Me.Filter = "Names Like '*" & [Forms]![regFAYT]![FindNames] & "*'"
Me.FilterOn = True

Me!FindNames.SelStart = 0
Me!FindNames.SelLength = Len(FindNames.Text)


End Sub

Actually bit confused at this minute as does not seem to be moving onto the next control at the moment no matter what I do. Sure use to. I know this is effectively re-querying so perhaps updating in a loop but odd as sure used lots of times, will investigate but sorry to post an incomplete question now..
 
The best I have managed so far is

Private Sub FindNames_AfterUpdate()
FindNamesUpdated = True
End Sub

Private Sub FindNames_Exit(Cancel As Integer)
Me.Filter = "[Names] Like '*" & [Forms]![regFAYT]![FindNames] & "*'"
Me.FilterOn = True

Cancel = True ' Cancel either way, but focus still stays here, needs the Setfocus to move on so unfortunatley now allow normal tab

If Not FindNamesUpdated Then Me!Reset.SetFocus ' still runs below FindNamesUpdated = False

FindNamesUpdated = False

End Sub

This actually works, FindNames is automatically highlighted I guess on the re-filter

The Cancel = True is the main help but what I don't understand is without the SetFocus it will stay on FindName even with the Cancel no matter what. It would be nice if it could tab away or directly Alt X to exit etc.
I can probably use Keydown etc but again always seems unnecessary.
 
Hi,

Thanks for your advise.
In the end I thought i would try a different approach.

I use AllenBrowne FAUY, find as you type, a lot & is really great as don't get any of these problems.
I assumed perfect for just one field search but always avoided if wanted to filter on 2 or more fields assuming would be slow'ish & needed some re-coding.

Anyway adapted so can use more than just the one search criteria (not as slick as AB's as lost dropdown) but found works great (even better than I imagined) & still pretty fast.
I have 2,3 or more filter criteria text boxes working on different fields.

I have in on a table with 10,000 records and works fine, I guess if considerably larger may slow but I think will cope with quite a size and sure my coding & tables even are in-efficent.
 
Just a thought:

My approach would be to use cascading combo boxes instead of a search box to cover more than one field
 

Users who are viewing this thread

Back
Top Bottom