Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
Bug with SelLength? (Excel 2000) John Coleman Excel Programming 0 October 18th 05 06:05 PM
Highlight / "Selection" of AutoShape Text (Like SelStart for TextBoxes) James Cox[_2_] Excel Programming 0 May 18th 05 06:05 PM
Form Focus and SelStart Geoff[_9_] Excel Programming 0 April 4th 05 07:20 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 08:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"