Converting Text Entries to Upper Case

G

GSR

Hi,

In general, I want to ensure that any entries by a person
into a form are converted to upper case characters as the
character is entered into the field, even if the caps
lock is on. The following code is fine, but this would
have to be applied for each field on the form.

Private Sub txtEmplyLName_KeyPress(KeyAscii As Integer)
Dim strCharacter As String
strCharacter = Chr(KeyAscii)
KeyAscii = ASC(UCASE(strCharacter))
End Sub

Given the example above, is it possible to create a
public function w/in a module that would perform the same
task?

Any guidance or suggestions would be most appreciated!!
 
A

Allen Browne

Not sure I would like an application that forced everything into upper case,
but if you are determined to do so, here's how:

1. Paste this function into a standard module (on the Modules tab of the
Immediate window):
Function UpCaseAlpha(KeyAscii As Integer)
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End If
End Function

2. In the KeyPress event procedure of the Form (not a text box), enter:
Call UpCaseAlpha(KeyAscii)

3. Set the form's KeyPreview to Yes.

4. Repeat steps 2 and 3 for other forms that should behave this way.
 
A

Alphonse Giambrone

My favorite is:

In a standard module, paste the code
Public Function MakeUpper()
If Not IsNull(Screen.ActiveControl.Value) Then
Screen.ActiveControl.Value = Trim$(UCase(Screen.ActiveControl.Value))
End If
End Function

If you are not running any other code in the AfterUpdate event of your
textbox, set it to
=MakeUpper()

This has the advavtage of allowing you to select multiple controls in design
view and applying it to all at once. A great time saver.

If you need to run additional code in the AfterUpdate event, then instead of
setting the event to =MakeUpper(), write your code as usual and just add the
line
Call MakeUpper

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top