Here is a little modified version of jcis's code that works on SingleLine textboxes.
This is actually a MultiLine text box, but it simulates like a singleline textbox.
Set Multiline = True and Scrollbar = Horizontal at designtime.
VB Code:
Option Explicit Private Declare Function ShowScrollBar Lib "user32" _ (ByVal hWnd As Long, ByVal wBar As Long, _ ByVal bShow As Long) As Long Private Const SB_HORZ = 0 Private Sub Form_Load() CheckScrollBars End Sub Private Sub Text1_Change() CheckScrollBars End Sub Private Sub CheckScrollBars() If Me.TextWidth(Text1.Text) > (Text1.Width - 100) Then 'Wider than width? ShowScrollBar Text1.hWnd, SB_HORZ, True 'Make HScrollbar visible Else ShowScrollBar Text1.hWnd, SB_HORZ, False 'Hide HScrollbar End If End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 10 Or KeyAscii = 13 Then KeyAscii = 0 End Sub




Reply With Quote