Problem SelStart and SelLength

R

RB Smissaert

Have a plain multiline textbox on a userform and trying to
highlight a particular bit of text according to an Interbase
SQL statement error.

This is the code:

Sub HightlightSQLError(strError As String)

Dim arr
Dim strStringToFind As String
Dim lColumnUnknown As Long
Dim lTableUnknown As Long
Dim lTokenUnknown As Long

lColumnUnknown = InStr(1, strError, "Column unknown", vbTextCompare)
lTableUnknown = InStr(1, strError, "Table unknown", vbTextCompare)
lTokenUnknown = InStr(1, strError, "Token unknown", vbTextCompare)

If lColumnUnknown > 0 Then
arr = Split(Mid$(strError, lColumnUnknown), ",")
strStringToFind = Trim(arr(1))
With MainForm.SQLtxtStatement
.SetFocus
.SelLength = 0
.SelStart = _
InStr(1, .Text, strStringToFind, vbBinaryCompare) - 1
.SelLength = Len(strStringToFind) + 1
End With
Else
End If

End Sub

It works fine first time, but after that the right bit of text is not
highlighted anymore, although the values
for SelStart and SelLength are found fine.
Strangely when I right-click the textbox the right bit of text does show
highlighted.
I can't use the right-click though as it has a popup menu.

Maybe it is better if I change this textbox to a rich-text box.

Thanks for any advice in this.


RBS
 
R

RB Smissaert

I figured this out now.
The trick is to move out of that textbox and back in again, so my relevant
bit of code is now like this:

With MainForm.SQLtxtStatement
.SetFocus
.SelStart = _
InStr(1, .Text, strStringToFind, vbTextCompare) - 1
.SelLength = Len(strStringToFind)
MainForm.SQLtxtTitle.SetFocus 'this is the essential bit
.SetFocus
End With

All working fine now.

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Keydown and SelStart problem 2
Read A Text File 2
shorten a macro 2
Lock colon in textbox 1
Intersect and Union 2
Highlight Value of Text Box 1
Array coding type mismatch 6
lists not populating userform 1

Top