Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP Textbox control 1

Status
Not open for further replies.

Phil Thoms

Programmer
Oct 31, 2005
245
GB
I have created a textbox within a form. How do I search a database with what is typed into the textbox ?
 

In interactveChange Event of the TextBox, In LostFocus Event of the TextBox or Everywhere else you want:
Code:
SEEK thisform.Text1.value IN MyTable ORDER MyOrder
I assumed that Text1 is the name of the TextBox

Borislav Borissov
 

philthoms,

Just to add to Borislav's good advice:

To use Borislav's example, you will need an index (called MyOrder in his code), the key of which must match what you are searching for. Check the Help re indexes if you are in doubt about this.

It's also advisable to wrap the search term in an ALLTRIM(), to avoid the effect of any trailing spaces.

Finally (to answer your question in your other thread), all that the SEEK does is to move the record pointer to the record in question (or to end of file if the record is not found). You still have to do something to make that record visible within your user interface.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Searching for Text in a VFP Textbox. I have done what has been suggested but as I type in the reference I am searching for, the pointer jumps to the bottom of the database, in other words it is not giving the user time to type in the FULL reference. Obviously I am missing something out from the code.
Thanks for your help in anticipation.
 

If it's jumping to the bottom of the table, that means that it is not finding the text the user has entered.

What about case sensitivity? The user might be typing in lower case, but the value in the table might be upper case. The usual solution is to use UPPER() in your index expression, and to wrap the search term in an UPPER() in the SEEK command.

Also, I'd suggest you put the code in the LostFocus rather than the InteractiveChange, to avoid having to run the SEEK at every keypress. But it's up to you.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
If you put the code in InteractiveChange then you need SET EXACT OFF. Otherwise Fox will respond to your first keypress and it'll fail to find anything which matches that single character. SET EXACT OFF will allow Fox to be satisified with a partial match.

The alternative as Mike suggests is to put the code in the LostFocus so as it deosn't fire until the user leaves the control.

Geoff Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top