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?

cdthurmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.