Use of Pseudo Custom Controls with Class Modules (1 Viewer)

coypu

Registered User.
Local time
Today, 12:59
Joined
Mar 12, 2019
Messages
26
Building on MajP’s very helpful post,
https://www.access-programmers.co.u...do-custom-controls-with-class-modules.321016/
here’s a simple class that strips CrLf’s from a single row textbox. Why would you want to do that? Well, when you copy & paste, say from a webpage, it often happens that you pick up some CrLf’s as well and if one of those is on the first line, your textbox would look empty. This class avoids that problem.

The technique of dynamically adding functionality to a control’s events from a class, creates so much potential. Thanks MajP.
Code:
Option Compare Database
Option Explicit

'Pseudo custom control to remove CrLf, usually from pasted text, e.g. from the web, into a single row textbox

Private WithEvents mstrTextBox As Access.TextBox

Public Sub Initialize(pTextBox As Access.TextBox)
  'Add this to calling forms
  '  Private mFixPasteText As FixPasteText
  '
  '  Private Sub Form_Load()
  '    Set mFixPasteText = New FixPasteText
  '    mFixPasteText.Initialize Me.Text0
  '  End Sub

  Set mstrTextBox = pTextBox
  'Ensure that events are raised
  mstrTextBox.AfterUpdate = "[Event Procedure]"
End Sub

Private Sub mstrTextBox_AfterUpdate()
  'Remove CrLf from textbox value so that the value can all be seen in single row control
  With mstrTextBox
    If .Height < 340 Then           'textbox is likely just a single row
      If .CanGrow = False Then      'and it can't grow
        Dim str As String
        str = Replace(.Value, vbCrLf, " ")
        .Value = Trim(str)
      End If
    End If
  End With 
End Sub
 

Users who are viewing this thread

Top Bottom