Apply filter prevents moving to next control, want to highlight to replace

bignose2

Registered User.
Local time
Today, 06:34
Joined
May 2, 2010
Messages
251
Tricky to explain but spent ages on this & should be simple but can't work out.

Have a text box I use for searching.
but after pressing enter to search I want it to highlight the existing text ready to type over the top of it without using delete button.
Basically type e.g. JONES
if result are not what I want just type SMITH (without deleting back over)

Private Sub SearchMain_AfterUpdate()

DoCmd.ApplyFilter "EmailPasteSearch"

Me.SearchMain.SelStart = 0
Me.SearchMain.SelLength = Len(Nz(Me!SearchMain, ""))

' Me.DummyField.SetFocus ' does not seem to move auto, perhaps the applyfilter refreshes & stays put
End Sub

This works, filter applied & my list is filtered.

However the cursor is at the start of the text & not highlighted.

I have the same code in got focus.
I notice running applyfilter it does not auto tab/move to the next field

I can't even setfocus to a dummy field and setfocus back, errors, can't move to ... tried in all events. gotfocus,enter etc. not sure why error'ing. Had a DoEvents & tried so many things.

I suspect the apply filter is refreshing everything but I still can't see why I can't highlight the textbox.

I have this working elsewhere but on some quite complicated code that does a variety of things and I wrote this a long time ago & trying to trace is tricky.

Any ideas
thanks I/A
 
When you apply filter, you remove out of the underlying Record-Set the filtered-out records. If the next search is for records filtered-out in the previous search, these records will not be found.

try using DoCmd.FindRecord instead of DoCmd.ApplyFilter.

Note: you first set the focus on the field you want to match to (see OnlyCurrentField parameter), so in your case you would have to first set to the field you want to tmatch to. the backe to the textBox.
Here you may find other ways to use findRecord.

ATB
 
Hi,

Did not explain myself very well,

the filtering is fine, work exactly as I want,

It is actually just entering the new search text into the text box that is annoying.

I want it to highlight what I have just typed, so I can quickly retype something else.
Should be such a simple easy thing but driving me nuts.

e.g.
Type SMITH & enter
form is filtered.
I then want SMITH highlighted & selected so I can type JONES without manually deleting. If I manually delete SMITH & type JONES the filtlering is fine.

Thanks anyway.
 
after applying the filter, you SetFocus
to the textbox where you are filtering
(provided it is in same form):

Me.Filter = "[FieldNameToFilter] Like '*" & Me.SearchMain & "*'"
Me.FilterOn = True
Me.textboxName.SetFocus

If it is in subform:

Me.SubformName.Form.TextboxName.Setfocus
 
It is actually a query that I am applying as a filter, quite complex so a query was easiest.

What I have found is that if I put the apply filter in On_Exit as opposed to after update it does work, I would prefer update but that is fine.

Causing a slightly different issue I am sure I can easily fix but not sure I will have a clean solution.

Now what I think is happening is the ApplyFilter requerys the form as expected, focus goes from the control but comes back to the same control/textbox after the filtering, & focus stays there. (it does nto move as in tab order, this does same a little strange but sort of understandable)
In my case now actually stuck in a loop as if I click my exitform or leave this control (OnExit) it filters again & return so never leaves.

As I say I can code to have it know that I have either cleared/deleted the search text or perhaps if it is the same it clears it & does not re-filter so allowing to to move on, but as I say not perhaps a nicely coded solution

Not very clear I know but difficult to explain.

I do wonder if more because it is apply filter (Query) and not using me.filter on etc.
 

Users who are viewing this thread

Back
Top Bottom