LOCAL lcSofar, lnSelect, lnSelStart, lnSelLength
WITH This
*** Get the value typed in so far
lnSelStart = IIF( LASTKEY() # 127, .SelStart, .SelStart - 1 )
*** Handle and empty value in the text box
IF lnSelStart = 0
.Value = ''
.SelStart = 0
GO BOTTOM IN ( .cAlias )
SKIP IN ( .cAlias )
ELSE
lcSofar = LEFT( .Value, lnSelStart )
.Value = lcSoFar
*** Use seek to find the record if a tag was provided
IF ! EMPTY( .cTag )
IF SEEK( UPPER( lcSoFar ), .cAlias, .cTag )
.Value = EVAL( .cAlias + '.' + .cField )
ENDIF
ELSE
*** Otherwise, save the current work area before swithching to the specified table
lnSelect = SELECT()
SELECT ( .cAlias )
*** And locate the specified record
LOCATE FOR UPPER( ALLTRIM( EVAL (.cField ) ) ) = UPPER( lcSoFar )
IF FOUND()
.Value = EVAL( .cAlias + '.' + .cField )
ENDIF
SELECT ( lnSelect )
ENDIF
ENDIF
*** If we need to refresh the parent container (usually a form or a page, do it here
IF .lRefreshParent
.RefreshParent()
ENDIF
*** Highlight the portion of the value after the insertion point
.SelStart = lnSelStart
lnSelLength = LEN( .Value ) - lnSelStart
IF lnSelLength > 0
.SelLength = lnSelLength
ENDIF
*** If we have refreshed the controls in the parent container, there are timing issues to overcome
*** Even though .SelStart and .SelLength have the correct values at this point, the search box
*** does not appear highlighted correctly without this delay
=INKEY(.1)
ENDWITH
HTH
Marcia