Connecting Tech Pros Worldwide Forums | Help | Site Map

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

MLH
Guest
 
Posts: n/a
#1: Nov 13 '05
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?

MLH
Guest
 
Posts: n/a
#2: Nov 13 '05

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


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?
Allen Browne
Guest
 
Posts: n/a
#3: Nov 13 '05

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


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" <CRCI@NorthState.net> wrote in message
news:a12of154doj7vb2sd7hubuoh6mcqsff0gv@4ax.com...[color=blue]
>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?[/color]


MLH
Guest
 
Posts: n/a
#4: Nov 13 '05

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


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"
<AllenBrowne@SeeSig.Invalid> wrote:
[color=blue]
>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.[/color]

Allen Browne
Guest
 
Posts: n/a
#5: Nov 13 '05

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


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" <CRCI@NorthState.net> wrote in message
news:8p6of19srjtnqeok24aqirevk9k11e91qt@4ax.com...[color=blue]
> 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"
> <AllenBrowne@SeeSig.Invalid> wrote:
>[color=green]
>>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.[/color][/color]


MLH
Guest
 
Posts: n/a
#6: Nov 13 '05

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


>Don't bother with the Text bit.
10:4[color=blue]
>
>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.[/color]
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.
Terry Kreft
Guest
 
Posts: n/a
#7: Nov 13 '05

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


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" <CRCI@NorthState.net> wrote in message
news:a12of154doj7vb2sd7hubuoh6mcqsff0gv@4ax.com...[color=blue]
> 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?[/color]


David W. Fenton
Guest
 
Posts: n/a
#8: Nov 13 '05

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


MLH <CRCI@NorthState.net> wrote in
news:8p6of19srjtnqeok24aqirevk9k11e91qt@4ax.com:
[color=blue]
> 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).[/color]

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
MLH
Guest
 
Posts: n/a
#9: Nov 13 '05

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


This sounds good. I'll give it a shot.
[color=blue]
>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.[/color]

Closed Thread