Force user to use uppercase

Zydeceltico

Registered User.
Local time
Yesterday, 22:34
Joined
Dec 5, 2017
Messages
843
We have alphanumeric job numbers that all start with an uppercase letter - currently "A". Typical job number looks like: A732802001. Only the first character is a letter and I want it stored as uppercase.

I have lazy typing sidekick coworker who routinely types a lower case "a."

Aside from chastising him verbally, is there some way I can "code" him into making that letter uppercase?

Thanks,

Tim
 
Hi Tim. You could use an Input Mask or use the UCase() function.
 
I 2nd the motion for UCase - applied to the form control (BeforeUpdate should suffice).
 
hi @Zydeceltico

if your code is a specific number of letters and characters, you can set the InputMask property on the Data tab of the Property Sheet

1 letter and up to 9 numbers, make uppercase
>L#########

uppercase 1 letter and exactly 9 numbers
>L000000000
PropertySheet_InputMask_Uppercase 1 Letter 9 numbers.png


if you use an Event Procedure, for a control it is done on AFTERupdate. For a form, it would be done on the BeforeUpdate event
Code:
Private Sub Controlname_AfterUpdate()
   With Me.ActiveControl
      If IsNull(.Value) Then Exit Sub
      .Value = UCase(.Value)
   End With
End Sub
 
or you can force it to be Upper.
add code to the textbox's Change Event:
Code:
Private Sub Text0_Change()
    Dim iStart As Integer
    Dim iLength As Integer
    
    
    With Me.Text0
        iStart = .SelStart
        iLength = .SelLength
        
        .Value = UCase(.Text)
        .SelStart = iStart
        .SelLength = iLength
    End With
End Sub
 
The Change event is another option, but the disadvantage is that it executes for each character typed, not just the first one. Rather I'd choose InputMask or UCase, as theDBguy suggested

If InputMask is used, the user won't realize they typed a lowercase letter. You can also specify that the rest of the entry is numeric. The bad thing about a mask is that the user needs to be at the beginning of it when they start typing. This happens when they tab in, but if they click into the control, they might be in the middle (unless you change that with VBA). By default, the mask will show underscore (_) for each character expected -- that can be changed.

If the control AfterUpdate event is used, the change to uppercase (UCase) will be made when the user leaves that control (or presses Ctrl-S to save record), so the user will see their lowercase letter change to uppercase. But then, if you want to validate the code, it will be harder.

you've got options, Tim, depending how you want it to behave, and how much control you want over what is typed.
 
I must admit, I dislike inpur masks intensely.? I must be using them incorrectly.?
If you click into the midlle of one, that is where you start, and then the data entry fails.?
With no input mask, you can just type.?

I've always used the UCase method (or some other) after data entry.
 
I must admit, I dislike inpur masks intensely.? I must be using them incorrectly.?
If you click into the midlle of one, that is where you start, and then the data entry fails.?
With no input mask, you can just type.?
I've always used the UCase method (or some other) after data entry.

InputMasks can be inconvenient. When using them, could use the GotFocus event to see if there is a value and if so, let the user be where they clicked. But if not, put them at the beginning. InputMask can be very handy for validating characters. As a general rule, I'm not a big fan either -- especially for date/time because then you lose ability to enter in any format and for time, lose shortcuts like "4p" for 4:00 pm or 16:00 depending on how its displayed ~
 
Last edited:
if you use an Event Procedure, for a control it is done on AFTERupdate.
Why? Why edit the field, then after the update, update it again with UCase? Just so that you can commit the second change when the record is saved by the form?
I'm curious to know your thinking behind that.
 
Why? Why edit the field, then after the update, update it again with UCase? Just so that you can commit the second change when the record is saved by the form?
I'm curious to know your thinking behind that.
I'm referring to the CONTROL AfterUpdate event. Changes can't be made to the value in the control BeforeUpdate event. Alternately, the form BeforeUpdate event can be used, depending on when you want it to change.
 
I'm referring to the CONTROL AfterUpdate event.
I know, and I heard you the first time...
...for a control it is done on AFTERupdate
Changes can't be made to the value in the control BeforeUpdate event.
Well I either forgot that or didn't know. Thanks.
 
Changes can't be made to the value in the control BeforeUpdate event.
can't double check right now but thought you could if you referenced the control text property?
 
Hi Tim. You could use an Input Mask or use the UCase() function.
Hi Tim. A third option is to leave it lowercase and simply display it as uppercase by using the Format property of the control wherever you need to show the value (forms or reports). So, just let the user do what they do and simply enter ">" (without the quotes) in the Format property of the Textbox on your forms or reports. Cheers!
 
hi Tim,

and yet another option -- although if you STORE in uppercase, > won't be needed in the Format property ... but for those values already entered, it might be nice if you don't do an Update Query to change them

I think CJ may be right about using the TEXT instead of VALUE property on a control BeforeUpdate -- I don't know since I don't do it that way (maybe I should! Thanks for the idea, Chris)
 
chang it to:

With Me.AddressLine4
...
...
 

Users who are viewing this thread

Back
Top Bottom