How To Simulate an Incremental Search from a Text BoxArticle ID: Q136479Creation Date: 10-SEP-1995 Revision Date: 18-OCT-1996
The information in this article applies to:
SUMMARY
The combo box control has an Incremental Search property that, when set to
true (.T.), searches the Control Source of the combo box with each
keystroke. Thus, if a user types the string ABC, the table is searched
after each keystroke, first for the string A, then for the string AB, and
then for the string ABC. Although the text box control does not have this
property, you can simulate this action. Two examples are given in this
article, one for a form with a grid, the other for a simple form.
MORE INFORMATION
NOTE: These examples are case sensitive.
Example One - Form with a Grid
* The custom property holdvalue is used to store the string
* the user has entered
* Changing the focus will lose the string; you must save it * in order to continue buildingTHISFORM.HOLDVALUE = THIS.VALUE * This sets focus to the grid so that the located record is * displayed in the grid and the RecordMark is turned on for * the located recordTHISFORM.GRID1.SETFOCUS * Reset focus immediately to the text box where the user is * entering the stringTHISFORM.TEXT1.SETFOCUS * Reset value of text box to string user had entered before seekTHIS.VALUE = THISFORM.HOLDVALUE * This moves the cursor to the end of the string in the text boxTHIS.SelStart = LEN(THIS.VALUE) ELSE * Tests/traps for the ENTER keyENDIF * This resets the string to a null or empty string so the user can * start a new search without having to exit and re-enter the text * box.IF nKeycode = 13
* Tests/traps for the Backspace key
* Emulates the backspace key by removing the last character * from the stringIF nKeycode = 127 * If the new string is one or more characters, repeat the seek * on the new, shortened stringTHIS.VALUE = LEFT(THIS.VALUE, LEN(ALLTRIM(THIS.VALUE)) - 1)
* Refer to previous section for comments
* Moves the cursor to the end of the new string
ENDIF
* End Code Example
* The custom property holdvalue is used to store the string
* the user has entered
* Refresh form to show located recordTHISFORM.HOLDVALUE = THIS.VALUE * Return focus to text box to continue searchTHISFORM.REFRESH * Reset value of text box to string user had entered * before seekTHISFORM.TEXT1.SETFOCUS * This moves the cursor to the end of the string in the * text boxTHIS.VALUE = THISFORM.HOLDVALUE
ELSE
* Tests/traps for the ENTER key
* This resets the string to a null or empty string * so the user can start a new search * without having to exit and re-enter the text box.IF nKeycode = 13
* Tests/traps for the backspace key
* Emulate the backspace key by removing the * last character from the stringIF nKeycode = 127 * If the new string is one or more characters, repeat the seek * on the new, shortened stringTHIS.VALUE= LEFT(THIS.VALUE, LEN(ALLTRIM(THIS.VALUE))-1)
* refer to previous section for comments
* Move the cursor to the end of the new string
ENDIF
* End Code Example
|
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.