Proper cased textbox input

By | 2018-02-26

This function will automatically adjust the contents of a textbox to proper case, as input is being entered.

It’s not really an “in-depth” piece of code. Rather, it is just a simple something to help out beginners.

First, a function must be defined, which can be called from anywhere. Place the following code in a module.

Private Function Proper_Case(Text As TextBox)
    Text.Text = StrConv(Text.Text, vbProperCase)
    Text.SelStart = Len(Text.Text) ' get rid of the annoying input at the end of the set length
    Proper_Case = Text
End Function

Now, in the keypress event for a textbox you want to work with, place the following:

Private Sub Text1_KeyPress(KeyAscii As Integer)

    Proper_Case Text1

End Sub

Simple and to the point, this will ensure that your text inputs are “magically” proper-cased.

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.