469,647 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,647 developers. It's quick & easy.

A97 How to force uppercase alpha chars in a textbox on a form?

MLH
I have a textbox on a form into which an alpha-numeric string
of data is entered. I wish to force the casual user, who would
sometimes use upper case, sometimes not and sometimes MIX
the case - yes, believe it - to use UPPER case only.

I tried running UCASE on the string entered during the textbox's
BeforeUpdate event code. That did nothing but return some error
saying I couldn't do it there - some kind-a-race condition, I dunno -
can't change while updating - whatever!

Can I somehow use textbox's inputmask property to allow only
uppercase alpha-numeric strings 2B entered?
Nov 13 '05 #1
8 31168
MLH
And, if I can not use inputmask to filter out lower-case alpha
chars, can I force a conversion of what's being entered keystroke-
by-keystroke in a keydown event procedure?
Nov 13 '05 #2
Use UCase() in the *AfterUpdate* event of the text box to convert the case.

You can place a > in the Format event of the text box to force the display
(but not stored value) to upper case. Don't do this with memo fields: it
truncates to 255 characters.

It is also possible to use the KeyPress event to alter the KeyAscii to the
upper case version of the entry. You still need the AfterUpdate event as
well, in case the user pastes text in.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.net> wrote in message
news:a1********************************@4ax.com...
I have a textbox on a form into which an alpha-numeric string
of data is entered. I wish to force the casual user, who would
sometimes use upper case, sometimes not and sometimes MIX
the case - yes, believe it - to use UPPER case only.

I tried running UCASE on the string entered during the textbox's
BeforeUpdate event code. That did nothing but return some error
saying I couldn't do it there - some kind-a-race condition, I dunno -
can't change while updating - whatever!

Can I somehow use textbox's inputmask property to allow only
uppercase alpha-numeric strings 2B entered?

Nov 13 '05 #3
MLH
Thanks, Allen. Do you recommend I use something like
Me!MyField.Text = UCase(Me!MyField.Text)
or can I just use
Me!MyField = UCase(Me!MyField) ? I tried the former
in the OnLostFocus event code. But, it seemed to generate another
Update event (unwanted).

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx

On Fri, 12 Aug 2005 11:02:47 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
Use UCase() in the *AfterUpdate* event of the text box to convert the case.

You can place a > in the Format event of the text box to force the display
(but not stored value) to upper case. Don't do this with memo fields: it
truncates to 255 characters.

It is also possible to use the KeyPress event to alter the KeyAscii to the
upper case version of the entry. You still need the AfterUpdate event as
well, in case the user pastes text in.


Nov 13 '05 #4
Don't bother with the Text bit.

You're alergic to the AfterUpdate event? It's the one that runs after a
change, and if there was no change you don't need it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.net> wrote in message
news:8p********************************@4ax.com...
Thanks, Allen. Do you recommend I use something like
Me!MyField.Text = UCase(Me!MyField.Text)
or can I just use
Me!MyField = UCase(Me!MyField) ? I tried the former
in the OnLostFocus event code. But, it seemed to generate another
Update event (unwanted).

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx

On Fri, 12 Aug 2005 11:02:47 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
Use UCase() in the *AfterUpdate* event of the text box to convert the
case.

You can place a > in the Format event of the text box to force the display
(but not stored value) to upper case. Don't do this with memo fields: it
truncates to 255 characters.

It is also possible to use the KeyPress event to alter the KeyAscii to the
upper case version of the entry. You still need the AfterUpdate event as
well, in case the user pastes text in.

Nov 13 '05 #5
MLH
>Don't bother with the Text bit.
10:4

You're alergic to the AfterUpdate event? It's the one that runs after a
change, and if there was no change you don't need it.

Ha! You got me on that one. Yeah, I had so much going on in the
afterupdate event code, I didn't wanna throw more in the mix, if I
could help it. But, I'll try it. I'm sure it'll work. Thx.
Nov 13 '05 #6
Use the keypress event

Private Sub Text0_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

this will then convert the user input to upper case as they input it.
--
Terry Kreft
MVP Microsoft Access
"MLH" <CR**@NorthState.net> wrote in message
news:a1********************************@4ax.com...
I have a textbox on a form into which an alpha-numeric string
of data is entered. I wish to force the casual user, who would
sometimes use upper case, sometimes not and sometimes MIX
the case - yes, believe it - to use UPPER case only.

I tried running UCASE on the string entered during the textbox's
BeforeUpdate event code. That did nothing but return some error
saying I couldn't do it there - some kind-a-race condition, I dunno -
can't change while updating - whatever!

Can I somehow use textbox's inputmask property to allow only
uppercase alpha-numeric strings 2B entered?

Nov 13 '05 #7
MLH <CR**@NorthState.net> wrote in
news:8p********************************@4ax.com:
Do you recommend I use something like
Me!MyField.Text = UCase(Me!MyField.Text)
or can I just use
Me!MyField = UCase(Me!MyField) ? I tried the former
in the OnLostFocus event code. But, it seemed to generate another
Update event (unwanted).


Well, you either need to test for IsNull() and not do it, or
concatenate the field with a zero-length string, or this will error
out any time the field is Null.

Either:

Me!MyField = UCase(Me!MyField & vbNullString)

Or:

If Not Isnull(Me!MyField) Then
Me!MyField = UCase(Me!MyField)
End If

In my code, most often I want to do nothing at all in the
AfterUpdate event when the value has been deleted, so I just exit
the sub, rather than repeatedly testing:

If Isnull(Me!MyField) Then Exit Sub
[whatever you'd do if it's not null]

But I can conceive of things that you might want to do in
AfterUpdate if a field is Null, so that isn't always the case.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
MLH
This sounds good. I'll give it a shot.
Use the keypress event

Private Sub Text0_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

this will then convert the user input to upper case as they input it.


Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Fredrik Kronander | last post: by
2 posts views Thread by Richard MSL | last post: by
4 posts views Thread by Tina | last post: by
7 posts views Thread by OHM | last post: by
1 post views Thread by Randy Fraser | last post: by
7 posts views Thread by DazedAndConfused | last post: by
3 posts views Thread by =?Utf-8?B?Sm9zZXBo?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.