Possible Match in Textbox

  • Thread starter Thread starter GW
  • Start date Start date
Can you please explain little bit more about SelStart and
SelLength. Please post sample code here if you can.

GW
 
Can you please explain little bit more about SelStart and
SelLength. Please post sample code here if you can.

I was a bit vague because you did not say where you would get the hint
values from. I guess it's something like this (as you may guess, this is
untested air code):-

Private Sub txtMyData_Change()

Dim strOld as String
Dim strNew as String

' preserve the current value
' if it's empty, coerce the Null into an empty string
strOld = txtMyData.Text & ""

' don't bother if it's empty
If Len(strOld) = 0 then Exit Sub

' get the hint from somewhere: this could be list of values
' or a recordset or whatever
strNew = GetLookupValue(strOld)

' if there's nothing to show, give up
' Note that Len() is much faster than string comparison
If Len(strNew) = Len(strOld) Then Exit Sub

' okay, put the new string into the textbox
txtMyData.Text = strNew

' set the selection to the non-overlapping part
' for example, if it's "Davi" and "Davies", then
' you want to highlight the "es"
txtMyData.SelStart = Len(strOld)
txtMyData.SelLength = Len(strNew) - Len(strOld)

End Sub



Hope that helps


Tim F
 
I understand this now :) Thank you for your help!!!

I am sorry about my last post. I was expecting reply
sonner than you did. And I thought this forum is too busy
for you to find this thread.
 
I am have been loooking around for the lookup code to get
from tablet or query to put value in 'strNEW' String

When I find it I ll post it in here
 
I am have been loooking around for the lookup code to get
from tablet or query to put value in 'strNEW' String

select top 1 SomeValue
from MyTableOfValues
where SomeValue LIKE [OldValue] & "*"
order by SomeValue

it might be one of those occasions when it's quicker to keep a recordset
open, but I'm not sure: depends on the server and the network:-


' use statics so that you don't have to keep re-opening
' the recordset, which is the point...
static rs as recordset
static db as database


' first time round, create the objects
if db is nothing then set db = currentdb()
if rs is nothing then set rs = db.openrecordset( _
"select all somevalue from mytableofvalues order by somevalue;", _
dbOpenSnapshot) ' not forwardonly!

' okay, this is the lookup
rs.findfirst "somevalue like """ & strOldValue & "*"""

' now decide what you want to return
if rs.nomatch then
' user has started a completely new value
strNewValue = strOldValue

else
' recognised: return the whole lot
strNewValue = rs!SomeValue

endif

Again: not tested so treat it with a bucketful of salt, but should be
somewhere close.

Hope it helps


Tim F
 
Back
Top