How to move scroll bar position to bottom or top after text box update (1 Viewer)

omnialive

Registered User.
Local time
Today, 08:29
Joined
Sep 17, 2010
Messages
23
What I have is a form, ProcessStatusWindow, that has a text box, status, with vertical scrollbar enabled. As my application does its work, it puts updates to the status text box using this method:

Code:
Global statusfrm As [Form_Process Status Dialog]
Set statusfrm = New [Form_Process Status Dialog]

Public Sub updateStatus(strStatUpdate As String)
  statusfrm.status.Value = strStatUpdate & vbCrLf & statusfrm.status.Value
End Sub

I call updateStatus("status updates") in my code and the update is done fine. As you can see, it is currently putting the latest update at the top of the text box value. I want to know how to move the scroll bar, after this type of update, to the bottom most text so that I can put the text in the proper chronological order instead of how it is now.

Essentially as new text is added to the box I want it to automatically scroll down with the new additions. Any ideas? I've searched around and can't find anything for VBA. Found something for VB6.

Any help is appreciated.
 

John Big Booty

AWF VIP
Local time
Tomorrow, 01:29
Joined
Aug 29, 2005
Messages
8,263
Use SelStart property and Len() function to place the cursor at the end of the text.

But given that you wish to append new text to the end of existing text try;
Code:
Me.TextBoxName = Me.TextBoxName & " " & NewTextString
 

omnialive

Registered User.
Local time
Today, 08:29
Joined
Sep 17, 2010
Messages
23
Use SelStart property and Len() function to place the cursor at the end of the text.

But given that you wish to append new text to the end of existing text try;
Code:
Me.TextBoxName = Me.TextBoxName & " " & NewTextString

Worked like a charm. Only thing I had to add was a "SetFocus" because it didn't like me using the SelStart without it. Two lines of code fixed my problem:

Code:
statusfrm.status.SetFocus
statusfrm.status.SelStart = Len(statusfrm.status.Value)

I knew I had to reverse how I was appending info to the status window. Here is the small module I created that handles this for me if anyone is interested:

Code:
Option Compare Database
Option Explicit

Global statusfrm As [Form_Process Status Dialog]
Global statusupdcnt As Integer
Global boolPermHideWindow As Boolean

Public Sub LoadStatusWindow()
 If Not IsLoaded("Process Status Dialog") Then
  Set statusfrm = New [Form_Process Status Dialog]
 End If
 
 If Not boolPermHideWindow Then
  statusfrm.Visible = True
 End If

End Sub

Public Sub updateStatus(strStatUpdate As String)
 If IsLoaded("Process Status Dialog") Then
  If (Len(statusfrm.status.Value) + Len(strStatUpdate)) > 65535 Then
    ''update will push text length past max allowed. Write to log and erase before update
    AddLogEntry statusfrm.status.Value, "INFO"
    statusfrm.status.Value = ""
  End If

  statusupdcnt = statusupdcnt + 1
  statusfrm.status.Value = statusfrm.status.Value & vbCrLf & statusupdcnt & ". " & strStatUpdate
  statusfrm.status.SetFocus
  statusfrm.status.SelStart = Len(statusfrm.status.Value)
 End If
End Sub

Public Sub CloseStatusWindow()
 If Not IsLoaded("Process Status Dialog") Then
  Set statusfrm = New [Form_Process Status Dialog]
 End If
 
 statusfrm.Visible = False
End Sub

Public Sub ToggleProcessStatusWindow()
 If Not IsLoaded("Process Status Dialog") Then
  Set statusfrm = New [Form_Process Status Dialog]
 End If

 statusfrm.Visible = Not statusfrm.Visible
End Sub
Public Sub ResetStatusWindow()
 If IsLoaded("Process Status Dialog") Then
  statusfrm.status.Value = ""
 End If
 statusupdcnt = 0
End Sub
Public Function IsLoaded(strFormName As String) As Boolean
'Purpose :To check wether a given form is loaded or not
'        :When referring to forms by name, the form must be open or access returns an error

    Dim i As Integer
    For i = 0 To Forms.Count - 1
        If (Forms(i).Name = strFormName) Then
            IsLoaded = True
            Exit For
        End If
    Next
End Function
 
Last edited:

omnialive

Registered User.
Local time
Today, 08:29
Joined
Sep 17, 2010
Messages
23
One thing I had to do is to check for the len of the status text to make sure it wasn't greater than 32767 (max size of integer) as SelStart is an integer!!! Very frustrating as the text box max length is 65535! Here is what I had to change:

Code:
  If (Len(statusfrm.status.Value) < 32767) Then
   statusfrm.status.SetFocus
   statusfrm.status.SelStart = Len(statusfrm.status.Value)
  End If

Hope this helps someone!
 

Users who are viewing this thread

Top Bottom