Home | What's New | Articles | Code Downloads | Tool Box | Links | Code Snippets  

Text Box

Disabling Textbox Popup menu
If you don't want the user to use the default right click edit menu you can easily replace it with your own using this code.

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbRightButton Then
    Text1.Enabled = False
    Text1.Enabled = True
    PopupMenu MyCustomMenu
  End If
End Sub

Scroll TextBoxes
You can make a TextBox scroll to the bottom with:

Text1.SelStart = Len(Text1.Text)

Make Return Act Like Tab
Set the form's KeyPreview property to true. In the form's KeyPress event handler, check for the carriage return. If you get one, use SendKeys to generate a TAB instead. Set KeyAscii to 0 so the carriage return is discarded

Private Sub Form_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
    SendKeys "{TAB}"
    KeyAscii = 0
  End If
End Sub

Preventing the User Typing Spaces into a Text box
This code prevents spaces being enter by setting KeyAscii to zero if KeyAscii is equal to a space.

Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 32 Then
                KeyAscii = 0
        End If
End Sub

Hidden Textbox features 

To see how to access features of the Text box control that aren't exposed directly in VB download the Textbox Features module from the Tool Box.