Problem with Addressbook-Search, using TextBox with OnChange-Event

asdf

New member
Local time
Today, 22:24
Joined
Apr 13, 2007
Messages
2
Hi everyone,

I'm working on an addressbook in my access database.
To search for address records I have implemented a Text Box('SearchText') on the top of my main Form('addressbook main'). This Text Box updates the record source of a continuous Subform below ('addressbook main list').
I'm using the "On Change"-Event so that the list will be updated automatically everytime the user types new textbox information.

Code:
-----

Private Sub SearchText_Change()

'Saving the Textbox input
DoCmd.RunCommand acCmdSaveRecord

'Updating the Subform
Forms![addressbook main]![addressbook main list].Form.RecordSource = "SELECT addressbook.* FROM addressbook WHERE (((addressbook.[name]) LIKE '*" & Me!SearchText & "*'));"

'Set Focus back to the Textbox
Forms![addressbook main]!SearchText.SetFocus

'Set Selection to the end of the textbox
If Not IsNull(Len(SearchText)) Then
Me!SearchText.SelStart = Len(SearchText)
End If

End Sub
-----

This actually works pretty good as long as my search consists of only one word.
If I try to type in a 'space'-character to start a new word it won't let me do it, because with saving, the "textbox-string" will always be trimmed on both sides and when moving the selection to the end of the textbox, it will always be after the last letter and not after the 'space' I typed.

Now, I have tried many things to fix this but I just can't come up with a way to keep the 'space'-character at the end.
Maybe somebody can come up with a different approach. I'm sure I'm not the first one who wants to use this kind of search method with using a Text Box.
I hope somebody will be able to help.
Thanks a lot in advance,

A.D
 
Here's a search database that refines the search every time you type in a new letter, and it also searches on multi-fields.

Credit to the unknown writer on these forums, I've used it many times.

Col
 

Attachments

That's just perfect,
thanks a lot!
 

Users who are viewing this thread

Back
Top Bottom