[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Autoscrolling TextBox in Outlook VBA

Posted on 2004-10-25
12
Medium Priority
?
1,252 Views
Last Modified: 2012-08-14
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
Comment
Question by:cdthurman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
12 Comments
 

Author Comment

by:cdthurman
ID: 12402717
Updated the points a little since it seems to be more difficult than I originally thought.
0
 
LVL 5

Expert Comment

by:gary_j
ID: 12403181
if clicking in the text box does the trick, try calling the txtInfo_click event from the "post" sub routine.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 1000 total points
ID: 12403225
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12405391
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
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12405407
But I think Erick37's ListBox idea is probably better for you...

;)

J.
0
 

Author Comment

by:cdthurman
ID: 12410765
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
 
LVL 32

Expert Comment

by:Erick37
ID: 12411026
A RichTextBox control will work, but you have to be licensed to use it (VB6 installed).
0
 

Author Comment

by:cdthurman
ID: 12414907
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
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12417115
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
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12417119
Oh, and don't forget to put End Sub at the end of it...

J.
0
 
LVL 8

Expert Comment

by:Ashutosh Vyas
ID: 12418603
TextBox1.SelStart = Len(TextBox.Text)

Would that do???

0
 

Author Comment

by:cdthurman
ID: 12433791
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question