Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force Uppercase in many fields on a form

Status
Not open for further replies.

Palmyra

Programmer
Jan 5, 2007
150
US
I have to force data input to uppercase on a form with many fields and I'd like to be efficient about it.

I know a simple Ucase function will work but I'd appreciate opinions about how to handle this.

Thank you.
 
Are we talking a VBA UserForm with textboxes? If so, does the input need to be uppercase during input or purely upon completion of the form?

This code makes each character uppercase as it is inputted. It is very efficient assuming you don't have too many textboxes or comboboxes to deal with. If you have 15+ textboxes, we can create a class module to deal with all of them and save code space.

Code:
Private Sub TextBox1_Change()

If Me.TextBox1.Text <> "" Then
    Me.TextBox1.Text = UCase(Me.TextBox1.Text)
End If

End Sub
 

On the other hand,if you're working with a Word document with FormFields that has been protected "for forms", each FormField allows you to specify Uppercase for all text entered. No coding necessary.

[glasses]


----------------------------------------------------------------------------------
[small][ponder]"Did you hear about the guy who refused to pay his exorcist?[/small]
He was repossessed." [lol]
 
Yes, vba user forms with text boxes. I may have 15+ text boxes on a form. It should be uppercase as inputted, so the code you suggested is what I had in mind.

What would the code in the class module look like? I just want to do this as efficiently as possible because I have to handle multiple forms as well.

Thanks for your help.
 

Try:
Code:
Private Sub TextBox1_Change()

Call UCaseTextBox(Me, TextBox1)

End Sub
and in the Module:
Code:
Public Sub UCaseTextBox(frmMyForm As Form, txtMyTextBox As TextBox)

If frmMyForm.txtMyTextBox.Text <> "" Then
    frmMyForm.txtMyTextBox.Text = UCase(frmMyForm.txtMyTextBox.Text)
End If

End Sub
(untested code)


Have fun.

---- Andy
 
This is about as efficient as it gets. I tested this behind a button.

Code:
Dim c As Control
For Each c In Me.Controls
    If TypeOf c Is TextBox Then
        c.Text = UCase(c.Text)
    End If
Next

I hope this helps.


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top