Auto capitalize all fields on a form

chanson

Registered User.
Local time
Today, 05:08
Joined
Mar 31, 2003
Messages
16
After digging around here and modifying some of the code I found, I wrote this simple little function to auto capitalize all of the fields on a form. It's pretty simple and I am sure that it has already been done but I thought it might help someone else out that is trying to do the same thing. All you need to do is put the following code in the BeforeUpdate event for your form.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Err
    Dim I As Integer
    
    For I = 0 To (Me.Controls.Count - 1)
        Me.Controls.Item(I).Value = UCase(Me.Controls.Item(I).Value)
    Next
    
Form_BeforeUpdate_Exit:
    Exit Sub
Form_BeforeUpdate_Err:
    If Err.Number = 438 Or Err.Number = 2448 Then
        Resume Next
    End If
    MsgBox Err.Description, , "#" & Err.Number
    Resume Form_BeforeUpdate_Exit
    Resume
End Sub

Hopefully this will help someone at some point that needs for all fields to be capitals
 
Last edited:
The code is useful but if you determine beforehand which fields you need in CAPS then just set the table properties to >
 
mark curtis: "The code is useful but if you determine beforehand which fields you need in CAPS then just set the table properties to > "

I usually also use the > in the property for objects in the form. If you don't do this, anytime you enter the control, the case will revert back to the way it was originally entered (i.e. it will revert from Uppercase to Lowercase) which I find somewhat disconcerting.

The Missinglinq
 

Users who are viewing this thread

Back
Top Bottom