This works pretty well, and it's easy, but it's not the ultimate solution.
The kludgey part is it uses a hidden field to incrementally capture the
keystrokes in the visible field (because executing code from KeyPress in the
visible field doesn't work - for some reason Access doesn't see the letters
until Exit or AfterUpdate is executed - maybe Refresh too). So you have to
make sure the data in the hidden field matches what's in the visible field.
You have to handle backspace at least - haven't tried other keys.
The Controls:
TextBox1 - visible, user enters search string here
TextBox2 - hidden, user doesn't see
ListBox1 - visible, show the results of the incremental search
The Routines:
Private Sub TextBox1_KeyPre ss(KeyAscii As Integer)
'ADD LETTERS TO HIDDEN TEXTBOX
If KeyAscii <8 Then
Me.TextBox2 = Me.TextBox2 & Chr(KeyAscii)
Else 'USER ENTERS A BACKSPACE
If Len(Me.TextBox2 ) 0 Then
Me.TextBox2 = Left(Me.TextBox 2 , Len(Me.TextBox2 ) - 1)
End If
End If
'CALL SEARCH ROUTINE
Call searchDB
End Sub
Public Sub searchDB(search Str)
'THIS VERSION DOESN'T USE WILDCARDS
cSQL = "SELECT FIELDS "
cSQL = cSQL & "FROM TABLE "
cSQL = cSQL & "WHERE ..."
If Len(Me.TextBox2 ) 0 Then
cSQL = cSQL & "AND LEFT(Trim(searc hField)," & Len(Me.TextBox2 ) & ") =
'" & Me.TextBox2 & "' "
End If
cSQL = cSQL & "ORDER BY ...;"
Me.ListBox1.Row Source = cSQL
End Sub
Enjoy! 5 6461
Not sure I have understood your question, but could you use the Change event
of Textbox1?
The Change event fires for each keystroke
Use the text box's Text property, i.e.:
Me.TextBox1.Tex t
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"DFS" <nospam@dfs_.co mwrote in message
news:du******** *********@bigne ws2.bellsouth.n et...
This works pretty well, and it's easy, but it's not the ultimate solution.
The kludgey part is it uses a hidden field to incrementally capture the
keystrokes in the visible field (because executing code from KeyPress in
the visible field doesn't work - for some reason Access doesn't see the
letters until Exit or AfterUpdate is executed - maybe Refresh too). So
you have to make sure the data in the hidden field matches what's in the
visible field. You have to handle backspace at least - haven't tried other
keys.
The Controls:
TextBox1 - visible, user enters search string here
TextBox2 - hidden, user doesn't see
ListBox1 - visible, show the results of the incremental search
The Routines:
Private Sub TextBox1_KeyPre ss(KeyAscii As Integer)
'ADD LETTERS TO HIDDEN TEXTBOX
If KeyAscii <8 Then
Me.TextBox2 = Me.TextBox2 & Chr(KeyAscii)
Else 'USER ENTERS A BACKSPACE
If Len(Me.TextBox2 ) 0 Then
Me.TextBox2 = Left(Me.TextBox 2 , Len(Me.TextBox2 ) - 1)
End If
End If
'CALL SEARCH ROUTINE
Call searchDB
End Sub
Public Sub searchDB(search Str)
'THIS VERSION DOESN'T USE WILDCARDS
cSQL = "SELECT FIELDS "
cSQL = cSQL & "FROM TABLE "
cSQL = cSQL & "WHERE ..."
If Len(Me.TextBox2 ) 0 Then
cSQL = cSQL & "AND LEFT(Trim(searc hField)," & Len(Me.TextBox2 ) & ") =
'" & Me.TextBox2 & "' "
End If
cSQL = cSQL & "ORDER BY ...;"
Me.ListBox1.Row Source = cSQL
End Sub
Allen Browne wrote:
Not sure I have understood your question, but could you use the
Change event of Textbox1?
The Change event fires for each keystroke
Use the text box's Text property, i.e.:
Me.TextBox1.Tex t
Thanks, but that doesn't work either.
It's like Access doesn't recognize what's in the textbox until you Exit,
AfterUpdate, or [maybe] Refresh. I don't want to use Refresh - even if it
does work - because the form is kind of heavy with other lists and may take
a while to refresh.
"DFS" <nospam@dfs_.co mwrote in message
news:du******** *********@bigne ws2.bellsouth.n et...
>This works pretty well, and it's easy, but it's not the ultimate solution. The kludgey part is it uses a hidden field to incrementall y capture the keystrokes in the visible field (because executing code from KeyPress in the visible field doesn't work - for some reason Access doesn't see the letters until Exit or AfterUpdate is executed - maybe Refresh too). So you have to make sure the data in the hidden field matches what's in the visible field. You have to handle backspace at least - haven't tried other keys.
The Controls:
TextBox1 - visible, user enters search string here TextBox2 - hidden, user doesn't see ListBox1 - visible, show the results of the incremental search
The Routines:
Private Sub TextBox1_KeyPre ss(KeyAscii As Integer)
'ADD LETTERS TO HIDDEN TEXTBOX If KeyAscii <8 Then Me.TextBox2 = Me.TextBox2 & Chr(KeyAscii) Else 'USER ENTERS A BACKSPACE If Len(Me.TextBox2 ) 0 Then Me.TextBox2 = Left(Me.TextBox 2 , Len(Me.TextBox2 ) - 1) End If End If
'CALL SEARCH ROUTINE Call searchDB
End Sub
Public Sub searchDB(search Str)
'THIS VERSION DOESN'T USE WILDCARDS cSQL = "SELECT FIELDS " cSQL = cSQL & "FROM TABLE " cSQL = cSQL & "WHERE ..." If Len(Me.TextBox2 ) 0 Then cSQL = cSQL & "AND LEFT(Trim(searc hField)," & Len(Me.TextBox2 ) & ") = '" & Me.TextBox2 & "' " End If cSQL = cSQL & "ORDER BY ...;" Me.ListBox1.Row Source = cSQL
End Sub
If you tested the suggestion, you must have either:
a) not used the Change event.
b) looked at the Value of the text box in its Change event instead of its
Text;
a) KeyPress is too early: the keystroke has not been processed yet. That's
the point of the event: you can destroy the keystroke (by setting KeyAscii
to zero.)
b) The Value of the control is not available until its BeforeUpdate event.
The Text property describes the contents of the control before it becomes
the Value.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"DFS" <nospam@dfs_.co mwrote in message
news:g9******** ********@bignew s5.bellsouth.ne t...
Allen Browne wrote:
>Not sure I have understood your question, but could you use the Change event of Textbox1?
The Change event fires for each keystroke Use the text box's Text property, i.e.: Me.TextBox1.Tex t
Thanks, but that doesn't work either.
It's like Access doesn't recognize what's in the textbox until you Exit,
AfterUpdate, or [maybe] Refresh. I don't want to use Refresh - even if it
does work - because the form is kind of heavy with other lists and may
take a while to refresh.
>"DFS" <nospam@dfs_.co mwrote in message news:du******* **********@bign ews2.bellsouth. net...
>>This works pretty well, and it's easy, but it's not the ultimate solution. The kludgey part is it uses a hidden field to incremental ly capture the keystrokes in the visible field (because executing code from KeyPress in the visible field doesn't work - for some reason Access doesn't see the letters until Exit or AfterUpdate is executed - maybe Refresh too). So you have to make sure the data in the hidden field matches what's in the visible field. You have to handle backspace at least - haven't tried other keys.
The Controls:
TextBox1 - visible, user enters search string here TextBox2 - hidden, user doesn't see ListBox1 - visible, show the results of the incremental search
The Routines:
Private Sub TextBox1_KeyPre ss(KeyAscii As Integer)
'ADD LETTERS TO HIDDEN TEXTBOX If KeyAscii <8 Then Me.TextBox2 = Me.TextBox2 & Chr(KeyAscii) Else 'USER ENTERS A BACKSPACE If Len(Me.TextBox2 ) 0 Then Me.TextBox2 = Left(Me.TextBox 2 , Len(Me.TextBox2 ) - 1) End If End If
'CALL SEARCH ROUTINE Call searchDB
End Sub
Public Sub searchDB(search Str)
'THIS VERSION DOESN'T USE WILDCARDS cSQL = "SELECT FIELDS " cSQL = cSQL & "FROM TABLE " cSQL = cSQL & "WHERE ..." If Len(Me.TextBox2 ) 0 Then cSQL = cSQL & "AND LEFT(Trim(searc hField)," & Len(Me.TextBox2 ) & ") = '" & Me.TextBox2 & "' " End If cSQL = cSQL & "ORDER BY ...;" Me.ListBox1.Row Source = cSQL
End Sub
Allen Browne wrote:
If you tested the suggestion, you must have either:
a) not used the Change event.
b) looked at the Value of the text box in its Change event instead of
its Text;
I thought for sure I had done both, so I went back and tested again. And
you're right - I must have missed one, because using the Change event and
the .Text property together worked. I was able to eliminate the hidden text
field and 7 lines of code. Result: cleaner and tighter system.
Thanks
a) KeyPress is too early: the keystroke has not been processed yet.
That's the point of the event: you can destroy the keystroke (by
setting KeyAscii to zero.)
b) The Value of the control is not available until its BeforeUpdate
event. The Text property describes the contents of the control before
it becomes the Value.
"DFS" <nospam@dfs_.co mwrote in message
news:g9******** ********@bignew s5.bellsouth.ne t...
>Allen Browne wrote:
>>Not sure I have understood your question, but could you use the Change event of Textbox1?
The Change event fires for each keystroke Use the text box's Text property, i.e.: Me.TextBox1.Tex t
Thanks, but that doesn't work either.
It's like Access doesn't recognize what's in the textbox until you Exit, AfterUpdate, or [maybe] Refresh. I don't want to use Refresh - even if it does work - because the form is kind of heavy with other lists and may take a while to refresh.
>>"DFS" <nospam@dfs_.co mwrote in message news:du****** ***********@big news2.bellsouth .net... This works pretty well, and it's easy, but it's not the ultimate solution. The kludgey part is it uses a hidden field to incrementall y capture the keystrokes in the visible field (because executing code from KeyPress in the visible field doesn't work - for some reason Access doesn't see the letters until Exit or AfterUpdat e is executed - maybe Refresh too). So you have to make sure the data in the hidden field matches what's in the visible field. You have to handle backspace at least - haven't tried other keys. The Controls:
TextBox1 - visible, user enters search string here TextBox2 - hidden, user doesn't see ListBox1 - visible, show the results of the incremental search
The Routines:
Private Sub TextBox1_KeyPre ss(KeyAscii As Integer)
'ADD LETTERS TO HIDDEN TEXTBOX If KeyAscii <8 Then Me.TextBox2 = Me.TextBox2 & Chr(KeyAscii) Else 'USER ENTERS A BACKSPACE If Len(Me.TextBox2 ) 0 Then Me.TextBox2 = Left(Me.TextBox 2 , Len(Me.TextBox2 ) - 1) End If End If
'CALL SEARCH ROUTINE Call searchDB
End Sub
Public Sub searchDB(search Str)
'THIS VERSION DOESN'T USE WILDCARDS cSQL = "SELECT FIELDS " cSQL = cSQL & "FROM TABLE " cSQL = cSQL & "WHERE ..." If Len(Me.TextBox2 ) 0 Then cSQL = cSQL & "AND LEFT(Trim(searc hField)," & Len(Me.TextBox2 ) & ") = '" & Me.TextBox2 & "' " End If cSQL = cSQL & "ORDER BY ...;" Me.ListBox1.Row Source = cSQL
End Sub
"DFS" <nospam@dfs_.co mwrote in
news:g9******** ********@bignew s5.bellsouth.ne t:
Allen Browne wrote:
>Not sure I have understood your question, but could you use the Change event of Textbox1?
The Change event fires for each keystroke Use the text box's Text property, i.e.: Me.TextBox1.Tex t
Thanks, but that doesn't work either.
It's like Access doesn't recognize what's in the textbox until
you Exit, AfterUpdate, or [maybe] Refresh. I don't want to
use Refresh - even if it does work - because the form is kind
of heavy with other lists and may take a while to refresh.
Are you sure? the .text property is by design, supposed to hold the
user's typed-in characters, while the control has focus.
the .value property, however behaves by design, as you describe,
unchanged until you ewxit the textbox.
I'd really like to see the .text property misbehave in the way you
describe, because that means there is a bug in Access :-)
--
Bob Quintal
PA is y I've altered my email address.
--
Posted via a free Usenet account from http://www.teranews.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: damjanu |
last post by:
Dear All;
I have 3 issues
1) On some of my tables I have unique indexes, so that
for example no two phone numbers can be the same.
When user enters phone number that already exists, a
scary error comes up with error number telling him
that it is a duplicate. I would like to catch this error
number xxxx and handle it so that I stop execution,
|
by: Colleyville Alan |
last post by:
I have an app that looks up an id number and when a button is clicked,
inputs the id # into a query. After running the query, I click a second
button which grabs the client name rather than the id for input to another
operation.
Originally, I had a drop-down box with the client name and the client id
number and it worked fine, but it was for a demo and was quick-and-dirty.
For the real app, there are over 1,700 client ids and the...
|
by: Colleyville Alan |
last post by:
I have a incremental search box that has been working fine for a couple of
months but is now acting up. This search box is from the cd that comes with
Getz's book, so I did not write it and have only a superficial understanding
of how it works.
I have had some trouble in the past when my code goes to another form and
comes back sometimes the search function did not work properly. Then I
added a line to requery it and it worked fine. ...
|
by: rh |
last post by:
Hi, I'd like to add an incremental search to my windows form DataGrid that
works like the one used in Windows Explorer.
In Windows Explorer, when you type a character it jumps to the first item
that matches that character. If you type another letter within a given
amount of time it will be part of the same search so that it will match the
first 2 characters and so on. If you wait long enough and then type another
character, it will treat...
|
by: Hrvoje Voda |
last post by:
I'm going through the listbox items with cursor.
I would like to put the selected listbox text into a textbox.
What method should I use?
Hrcko
| |
by: Luis Ferrao |
last post by:
Comming from Windows Forms development, I never had problems with this
issue before.
What i'm trying to achieve is an iTunes like incremental search. For
those who never used iTunes, it's basically a text field with a key
stroke event that filters the data grid as the users types in a string.
The more text in the field, the fewer fields desplayed.
The problem is that this is obviously a client side behaviour.
|
by: allansiu823 |
last post by:
Hi I am new to MS Access and VBA and have been bothered by this problem for a looooong time. I have this listbox containing all the records (~1000) in a form and I want to be able to type something in and match it with the matching record IN the listbox. I want it to work exactly like the "Find" function in the "Edit" Menu on the Toolbar, however the Find function does not search anything within the listbox.
I tried tp create a textbox and...
|
by: Eugenio |
last post by:
Hi there, I'm returning to this forum for the second time and I would like to say thanks for the great help provided. I've encountered a new problem now and hope that you will be able to help me again.
I'm currently implementing a container monitoring system in MSAccess07 and I'm using a multiple search function to sort containers. I use several unbound text boxes and a list box.The user type's in partial search criteria in one or several...
|
by: weirdguy |
last post by:
Hello,
Just for anyone information, there is a similar title "Search in Listbox" but it is via Combo Box. In case, anyone need it, I put a link to here.
Please let me know if I break any rules by posting a link so then, I will remove it.
Okay, here is my question. If you ever refer to the link, I am almost doing the same thing. Just that, I am doing a textbox and a combo box to search the listed data in the listbox.
The listbox...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |