Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Problem SelStart and SelLength
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Problem SelStart and SelLength
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 "RB Smissaert" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Started out as an Access problem. Now an Excel problem | Excel Discussion (Misc queries) | |||
Bug with SelLength? (Excel 2000) | Excel Programming | |||
Highlight / "Selection" of AutoShape Text (Like SelStart for TextBoxes) | Excel Programming | |||
Form Focus and SelStart | Excel Programming | |||
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? | Excel Programming |