• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1255
  • Last Modified:

Autoscrolling TextBox in Outlook VBA

I seem to be having trouble getting my textbox to autoscroll to the bottom and keep up with text.  Basically my textbox is a status window that displays information about current activities happening in the background and I would like it to remain at the bottom at the most current line.  I also want a max limit on the number of lines displayed in the window.  I have searched and tried many solutions previously posted.  Currently I have:

Const MAXCHARS = 10000

Sub Post (strNewText as String)
   With txtInfo
      If Len(strNewTxt) + Len(.Text) > MAXCHARS Then
         .Text = Mid$(.Text, InStr(100 + Len(strNewText), .Text, vbCrLf) + 2)
      End If
      .SelStart = Len(.Text)
      .SelText = strNewText
   End With
End Sub

That posts the information I need to the window properly and maintains the limit, but the scrollbar does not update and remain at the bottom of the window.  If I click in the textbox it updates and jumps to the bottom.  I tried setting focus to the textbox at the end of the post sub and also attempted a form repaint but neither gets the scrollbar to update properly.

Another solution I saw recommended SendMessage to send a scroll message to the scrollbar but when I try to use Form1.hWnd in Outlook vba I get an undeclared member.  Is there something I am missing or someway to get this darn textbox to autoscroll?

0
cdthurman
Asked:
cdthurman
  • 4
  • 4
  • 2
  • +2
1 Solution
 
cdthurmanAuthor Commented:
Updated the points a little since it seems to be more difficult than I originally thought.
0
 
gary_jCommented:
if clicking in the text box does the trick, try calling the txtInfo_click event from the "post" sub routine.
0
 
Erick37Commented:
You may consider using a ListBox instead...

With ListBox1

If .ListCount > 100 Then 'max 100 lines
.RemoveItem (1)
End If

.AddItem strNewText
.ListIndex = .ListCount - 1
.Selected(.ListCount - 1) = False

End With
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jimbobmcgeeCommented:
In a VBA.TextBox there are properties called CurLine and LineCount (they're not in the VB6 textbox -- I don't know why).  I would expect

        TextBox1.CurLine = TextBox1.LineCount

to do the job for you...

HTH

J.
0
 
jimbobmcgeeCommented:
But I think Erick37's ListBox idea is probably better for you...

;)

J.
0
 
cdthurmanAuthor Commented:
CurLine does not work either.  ListBox works fine but you cannot select/copy text from a list box.  Still trying to decide if that is needed or not.  Still hoping there is a way to get it to work with a TextBox.

0
 
Erick37Commented:
A RichTextBox control will work, but you have to be licensed to use it (VB6 installed).
0
 
cdthurmanAuthor Commented:
That's really not an option either.  Needs to be installed on quite a few machines and I don't have the rights to make registry changes to register DLLs for RichTextBox.
0
 
jimbobmcgeeCommented:
You can select/copy text from the listbox, you just need to fiddle about a bit:

Alongside your listbox (lstLog), place a 'Copy' commandbutton (cmdCopyLog).  Then, in the code for that button:

       Sub cmdCopyLog_Click()

             Clipboard.Clear
             Clipboard.SetText lstLog.Selected

HTH

J.
0
 
jimbobmcgeeCommented:
Oh, and don't forget to put End Sub at the end of it...

J.
0
 
Ashutosh VyasFounder, InitQubeCommented:
TextBox1.SelStart = Len(TextBox.Text)

Would that do???

0
 
cdthurmanAuthor Commented:
I asked the users and they said copy paste wasn't really an issue so going with the listbox solution.  I wish there was a way to do is using a plain ol' textbox but VBA doesn't want to play nice in Outlook.

Awarding points to Erick37

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now