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!

filter in combo box using cursor as data source 1

Status
Not open for further replies.

jworley

Programmer
Jun 19, 2000
36
GB
Hi, I have no room on my form for a list box, so I've used a combo box instead. An SQL query creates a cursor that I then use as the data source. What I really want is for the user to type the first character of a stock code they are looking for into the combo box. This should open the combo box, displaying all stock codes starting with that letter. Each time they type in a further character, I want to further filter the data source so that they end up with a group of stock codes they can make a final selection from.

I can't get the combo box to open and display all entries after they've typed in the first search letter (This is important). Subsequently, I tried using the following code in the keyPress method for the filter (but it only works for 1 character)


private m.lookup
store upper(chr(nKeyCode)) to m.lookup

select c_stock

set filter to left(c_stock.stock_code,1) == alltrim(m.lookup)

Any ideas/code anyone ?

Jim Worley
jim@aits-uk.net
15 years practical IT experience from sales to support to development plus B.Sc. (Hons) Computer Studies, fluent German speaker, willing to have a go at anything and don't suffer fools gladly !
 
Initialise the m.lookup at the form level as property say cLookUp with a stored value blank ( .not. .f. as default)

Replace the line
store upper(chr(nKeyCode)) to m.lookup
with
ThisForm.cLookUp = ThisForm.cLookUp+lastkey()

and then set filter to this

Ramani
 
instead of ThisForm.cLookUp you could use it as private m.lookup as well .. it is just a matter of preference and the varable shall be available for filter. Hence m.lookup will also work since it is a private variable.
The tip is that
you increment the m.lookup value with the lastkey() instead of replacing it.

ALSO IMPORTANT IS THAT - YOU SHOULD KNOW WHEN TO RESET THE m.lookup VALUE TO ITS BLANK VALUE SO THAT FRESH SEARCHES CAN BE MADE.

My real suggestion will be to use a lookup search form (we can create a generic - default data scession - search form with all key lookup facilities and call it in the interactive event of the required objects. This is much more easier and quicker to code in the long run !
 
There is some error in my previous code... hasty writing :(

lastkey() always returns numeric and so it shall be CHR() of the lastkey() value. However I have cut and pasted below from my routines suitably (which works fine for me).

The KeyPress event shall be
================================================
LPARAMETERS nKeyCode, nShiftAltCtrl

IF ! INLIST(nKeyCode,1,3,4,5,6,9,13,18,19,22,24,27)
WITH ThisForm
IF VAL(SYS(2)) < .nSeconds + 2
.cKeysPressed = .cKeysPressed + CHR(nKeyCode)
ELSE
.cKeysPressed = .cKeyPreFix + CHR(nKeyCode)
ENDIF
.nSeconds = VAL(SYS(2))
ENDWITH
SEEK (ThisForm.cKeysPressed) && or locate the record
&& Set focus to the control wanted
NODEFAULT
ENDIF
IF INLIST(nKeyCode,27)
&& Set focus to the control wanted
ENDIF
**
Hope it woks for you :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top