Simple Uper-case letter question

I'm working in a form and have set up some input boxes. They are set to "Text" and I would like to have the box set up so that if the data entry person puts in "c" or "C" it will automaticly make it a "C". I only want upper case letters and numbers to be put in the box. No lower case letters. If they are typed in, they will automaticly be changed to upper-case.

This sounds like a very SIMPLE thing to do. But I spent about 30minunits on this yesterday. It's easy to underline, bold, etc.

I went into "??" I forget what it was called and set up a string for it something like UpCse$ (??????).  I forget what it was but after doing that when I went into the box and try to change the letter to anything (upper or lower case) I got a message box stating that I had intered the wrong thing in that box.

Help!    :-)
Danny
dannycreechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dtomynCommented:
Try this,

Public Function KeyUpper(KeyAscii As Integer)
' Called from keypress event of an unbound textbox
' Forces upper-case entry

    KeyAscii = Asc(UCase(Chr(KeyAscii)))

End Function
0
dtomynCommented:
Wow, these times here at E-E sure act strange sometimes!  (i.e. I posted an answer apparently 33 minutes before the question was asked!)
0
dannycreechAuthor Commented:
I need a lot more detail about your answer above. I am VERY new at this. Does this have something to do with an "Event Procudure"?

Give it to me in little baby steps.

Thanks,
Danny
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

dtomynCommented:
Sorry,
Right-click on your text box and choose properties.  Then on the properties floating window click on the "Event" tab.  Scroll all the way to the bottom and find the "On Key Press" event.  Click the "..." button and choose "Code Builder".  From here type in the following:
Private Sub Text0_KeyPress(KeyAscii As Integer) 'You will alread be here
    Call KeyUpper(KeyAscii)
End Sub

Public Function KeyUpper(KeyAscii As Integer)
' Called from keypress event of an unbound textbox
' Forces upper-case entry

    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Function

Let me know if you have any more questions.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GabeSmedCommented:
If I understand what you want to do, make it so any lowercase letters in the text box are turned into uppercase letters, this is how you do it.

(This is for Access 97/2000)
Go to properties for the text box, and under 'Events', locate the 'After Update' property.  Click on the little down arrow that appears in the box besides the After Update property and select Event Procedure.  Now, click on the ... button (that is to the right of the box that now says [Event Procedure].

You should get something like this.

Function Textbox_AfterUpdate()

End Function

add this code in between Function and Endfunction, replacing Textbox with the name of your textbox that you want to be turned into Uppercase.

Textbox = UCase(Textbox)

This will make it so when the field that is linked to the textbox is updated, it will be automatically changed to Upper Case.  If you want it to be changed as you type, do the exact same thing as above but instead of putting the Event Procedure under 'After Update', put it on 'Change' (I'm not sure what is exactly called, but something like Change or Text Change)
Then it will be turned to uppercase as you type.

Regards,
Gabe Smedresman
0
BrianWrenCommented:
The windows operating system constantly monitors the keyboard, and when a key is pressed, 'message' is sent to the application currently having the focus.  If the key is held down, Windows will send repeated KeyPress messages.  When you release the key, a keyUp message is sent.  (MouseDown, MouseUp, and MoueMove messages are the same sort of thing.)  It is the application's responsibility to respond to the message.

If you set a control's or a form's KeyPress event, or KeyDown event, when Access receives a KeyDown message, it will run that procedure.

(KeyPress is an event that Access itself generates in response to the KeyDown message.)

To set a control's events, you select the event in question on the property sheet while designing the form, select {Event Procedure} from the drop-down list, then click the ellipsis button to the right. [...]

There is a specific format for each type of event procedure. Let's say you had a control named 'ctl.'  Its Click event would look like this:


----------------------
Private Sub ctl_Click()

End Sub
----------------------


But some procedures have arguments that Access generates and passes on to them.  Form instance form Open events have the format:


----------------------
Private Sub Form_Open(Cancel As Integer)

End Sub
----------------------


If the code in the event sets Cancel (which starts out = False) to = True, when the procedure is over and Access checks the value of Cancel, the form will stop opening, and Access will send the 'error' 2501, "operation cancelled" to the event that tried to open the form.

Where this will help you is that the keycode for the key that was pressed is one of the arguments to the KeyPress event, and the state of the Shift, Control and Alt keys is the other argument.  You can change these values, and Access will then act as if the changes you made were the original keystroke.


----------------------
Private Sub ctl_KeyDown(KeyCode As Integer, Shift As Integer)

End Sub
----------------------


The keycodes for "A" thru "Z" are 65 - 90, regardless of the state of the shift key.
The keycodes for 0 thru 9 on the numberpad are 96 - 105
The keycodes for 0 thru 9 on the Keyboard are 48 - 57

If you set KeyCode = 0 in the procedure, Access disregards the keystroke altoghether.

You will need to permit control keys like the arrow keys, Delete, etc.

After the Keydown event, the KeyPress event is fired, and you get a second shot at the key, where case DOES matter


----------------------
Private Sub Text4_KeyPress(KeyAscii As Integer)

End Sub
----------------------


Here "A" thru "Z" = 65 - 90, and "a" thru "z" = 97 - 122
If you change a KeyAscii = 97 to = 65, the case is changed.

So:


----------------------
Private Sub ctl_KeyDown(KeyCode As Integer, Shift As Integer)

    ' Let's make sure this is not a control key.
    If _
       KeyCode = 8 Or _
       KeyCode = 9 Or _
       KeyCode = 27 Or _
       KeyCode = 45 Or _
       KeyCode = 46 Or _
       KeyCode = 144 Or _
       KeyCode = 145 Or _
       KeyCode >= 16 And KeyCode <= 20 Or _
       KeyCode >= 33 And KeyCode <= 40 Or _
       KeyCode >= 112 And KeyCode <= 123 Then Exit Sub

    ' Now, if it's a digit off the number pad.
    If KeyCode >= 96 And KeyCode <= 105 Then Exit Sub

    ' Now number on KeyPad, but not shifted into !@#$...
    If KeyCode >= 96 And KeyCode <= 105 And Shift = 0 Then Exit Sub

    ' Now legitimate letters.
    If KeyCode >= 65 And KeyCode <= 90 And Shift = 0 Then Exit Sub

    ' In all other cases, discard the keystroke.
    KeyCode = 0

End Sub
----------------------


Now, to change the case for those that we kept:


----------------------
Private Sub ctl_KeyPress(KeyAscii As Integer)

    KeyAscii = Asc(Ucase$(Chr$(KeyAscii)))

End Sub
----------------------


Brian
0
brewdogCommented:
Wow, that was a little bigger comment than I expected to read in this thread, Brian. You've been reading Jim's comments, I see. :o) (BTW, congrats on being in the top 10 now!)

dannycreech: As you can see, everyone has basically the same idea. Brian is suggesting a changing of the letter's case as soon as the user types each letter. That seems like overkill to me. I'd go with dtomyn or GabeSmed's suggestion of putting the code on the AfterUpdate event of the text box, though I'd use this function instead:

TextBox = strConv(Textbox, vbUpperCase)

Access 97 added StrConv to convert the case of strings. Same idea as UCase or dtomyn's homemade function. I just like it better. :o)

brewdog
0
BrianWrenCommented:
How come nobody but me notices that dannycreech said "Nothing but upercase letter and numbers?"

What does strConv(Textbox, vbUpperCase), UCase(Textbox) or Asc(UCase(Chr(KeyAscii))) (by itself) do to prevent "ABD#$^^*~" from being entered?

That's a much bigger task, (and so was more of a challenge), hence the effort for a 25 point question.  What really tees me off, (and has impacted my whole Satruday!), was that I had entered a better answer, with a better explanation, and was about 2:00 min. from submitting it when my computer misfired, (I started Excel to sort the codes for the function keys, End, arrows keys etc.), and while the startup splash screen was still showing, my screen went to Black_N-White, with (apparently) 320×240 resolution, and all text the same color as the background.

I couldn't do anything.  Had to reboot, and was under a 'deadline,' (we had to go to a friend's daughter's piano recital), so I couldn't give as much effort to the thing the 2nd time around...

Phooey!

Thanks for the congrats, brewdog!

Brian
0
dtomynCommented:
>>How come nobody but me notices that dannycreech said "Nothing but upercase letter and numbers?"

Good point BrianWren... apparently some of us are not paying as much attention as you.  Considering this, your comment will probably be accepted as the answer since it seems to be covering all of the bases.
0
paaskyCommented:
Hello dannycreech,

I'm little confused what do you exactly are looking for (read comments above), but here are two ways to convert letters (quite easily):

1. Add this function into your form's code

Public Function Convert_Case()
    ActiveControl.Value = strConv(ActiveControl.Value, vbUpperCase)
End Function

To use it: write =Convert_Case() to AfterUpdate Event property of any TextBox in your form you like to convert uppercase.

2. Set > to TextBox's format property (this actually doesn't change the value stored into table, but users see text box value uppercase)

Hope this helps,
Paasky
0
rayfordCommented:
What I dont like about the Uppercase applied to the whole control is that it is easy to wind up with your cursor in the wrong place so those "Whole Control" UCase conversions are only good on the lost focus or before update events really.

Brian's posted the good stuff where I think if you intercept the Keypress change it to keyascii=keyascii-32 for keypress in the range 97-122 you should have what you want.

I was thinking of how to do this just the other day and tried the first method and was sad to note the cursor was thrown clear to the front of the entry everytime I tried to change with something like text4.text=ucase(text4.text) bleh.  What was I thinking?
0
rayfordCommented:
Just occured it might be a bit trickier to do an inline during edit
"Propercase" hmm Ucase is easy the 97-122 always gets dropped to 65-90 but with Propercase you would need to know the current active control to determine what exactly was in the box and to be sure it followed a dash or space or was the first character.  I love these little puzzles!
0
rayfordCommented:
I enjoy answering my own riddles and here was what I came up with.

On each textbox you want propercase INLINE while typing do something like this..

Private Sub Text19_Change()
    Text19 = StrConv(Text19.Text, 3)
    Text19.SelStart = Len(Text19)
    Text19.SelLength = 0
End Sub

:)
0
daks2003Commented:
Hi guys,

How about this

private sub txtBox_KeyPress(keyAscii as integer)

dim goodkey as boolean
goodkey = flase

if keyascii >=65 and keyascii <=90 then
     goodkey=true
else
    if keyascii >= 97 and keyascii <= 122 then
     keyascii = keyascii-32
     goodkey = true
else
    if keyascii >=48 and keyascii <=57 then
       goodkey = true
endif
endif
endif
if goodkey = false then keyascii = 0

end sub

First check if the key is in upper case, If it is then the key is valid.

Otherwise check if the key is in lowercase,if it is then translate it to lower case and then make it valid.

Otherwise check if the key is a number(0-9), If it is then make it valid.

If the key is not valid then make keyascii zero.
0
rayfordCommented:
I enjoy answering my own riddles and here was what I came up with.

On each textbox you want propercase INLINE while typing do something like this..

Private Sub Text19_Change()
    Text19 = StrConv(Text19.Text, 3)
    Text19.SelStart = Len(Text19)
    Text19.SelLength = 0
End Sub

:)
0
rayfordCommented:
whoops hit refresh I hate how it does that.  I thought Brian said it better but I guess he was holding out for a plug n play answer sheesh some guys are never happy...
0
BrianWrenCommented:
daks2003:  It is the custom in the Access area of EE thaat we answer by using comments, allowin ghte person who initially asked the question to decide which recommendation actually answers his question.

And the more so when there have been many suggestions.

What you have now done by proposing an answer is to take the question out of the 'Awaiting An Answer' section, reducing the liklihood that dannycreech will get a solution, if your 'answer' is not what he's looking for.

Would you please go back and convert your 'answer' to a 'comment?'

(Besides, your answer is very much like mine...)

Brian Wren
0
dannycreechAuthor Commented:
WOW! I thought this would be a simple thing.  :-)   I am very suprised this is NOT a "Standard" thing that a lot of business would want automaticly in a database. I figured for sure I was just over looking a place where I could just put a check mark or something stating to only allow uppercase letters. Hummm.

First, let me say THANK YOU to all of you for going at this little problem with such valiant effort! You guys really know your SH1t* I'm impressed.

Some of you have requested more information. HERE it is. What I am creating is a simple pilot logbook database. There are a few boxes that I want to have ONLY capital letters in. One of the boxes is for the Tail Number of the Aircraft. A sample tail number would be like this: N6579K   I plan on letting my girlfriend do the data entery of the information that is in my paper log book. I don't want her to accidently put in: n6579k.  Leter on, on the form, there is another box for the "Remarks" of the flight and I don't want the remarks to be in all caps. Otherwise, I would just have her leave the cap-lock on when she does the inputing. So, this is why I want to do what I am doing. There is another box that will contain the three letter/number airport idintifer. Here are a few examples: LAX, M1U, MAC    

NOTE****
One last thing about the airport idintifer box; This box will ALWAYS be a three letter/number idinitifer. Therefor, I would like the box to only allow three charitors and apon entering the last letter/number "autotab" into the next box.    HOW do I do this?

I will take this information home and give it a try on my database. When I get back here to the Library to answer my email, I will give credit to the person that answered the first question. Also, because this turned out to be a BIGGER question than I had thought it would be, I plan on giving the person that answered it 100 points.

Thanks,
Danny
0
daks2003Commented:
Sorry BrainWern,
I didn't know the coustom.

Daks2003
0
paaskyCommented:
dannycreech,

I think you should combine the KeyEnter/KeyDown functions suggested here and Input Mask property.

Automatic tab occurs when the last character permitted by a text box control's input mask is entered.

Here's an information how to use AutoTab with three letter field:

1. Set Input mask to AAA
(AAA = Letter or digit - entry required)
2. Set Autotab property to Yes

Regards,
Paasky
0
dannycreechAuthor Commented:
Dtomyn: Thanks your suggestion worked great.

BrianWren: That was an excellent explanation! Are you a teacher? If not, you should be. Because I did some GFA basic programming back in the mid-80s, I understand exactly what you said.

With regard to being able to enter "ABD#$^^*~"... At first, I thought "Way Cool", yes that is what I want. But after looking at the four boxes I want to do this with. All of them in different scenarios will use charters like # and -.

brewdog: I got it to work after I figured out what I needed to do.

Paasky: I hope I explained it better in this message. I wasn't able to understand your comment as to what you thought I should do. The "Write = " thing really confused me. Sorry.
I'll try the last thing you commented on when I get back home.


One thing I would like to point out to all of you Access Master Programmers is that us little guys don't always understand what you mean when you type code. Here is my example:
Brewdog gave me this: TextBox = strConv(Textbox, vbUpperCase)
Giving me something more along these lines would have worked better for me:
Put the name of your text box here = strConv(Put the name of your text box here, vbUpperCase)
I know this sounds over simplified to most of you guys. But I am a real newbe to VB.


I really did not think this would become this big of a deal. I think it is one of those things were one says something like "I'd sure like to do this". Then when you do that you decide "hey, if I can do that then I could take it one step forward and do this too". Next thing you know, you have done to much. :-)  This little logbook program is just that (Little/simple). You guys really are wonderful for putting forth 110%.


After reading all of your posts and trying them out. I decided to go with dtomyn. BrianWren, I wanted to give the points to you because you had an even BETTER answer! Only thing is, I would feel guilty giving you the points and using the code dtomyn gave me.

Thanks EVERYONE!
Danny


Here is the code I am actually using:

Private Sub AC_Make___Model_KeyPress(KeyAscii As Integer)
Call KeyUpper(KeyAscii)
End Sub
Private Sub AC_Tail_Number_KeyPress(KeyAscii As Integer)
    Call KeyUpper(KeyAscii)
End Sub
Private Sub From_KeyPress(KeyAscii As Integer)
    Call KeyUpper(KeyAscii)
End Sub
Private Sub TO_KeyPress(KeyAscii As Integer)
    Call KeyUpper(KeyAscii)
End Sub
Public Function KeyUpper(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Function
0
dannycreechAuthor Commented:
It looks like EE only gave 10points for this question and not the 100 points I put in. Am I reading this wrong? If not, please let me know how to give the extra 90 points. Maybe I did not hit the "0" slow enough for the computer to catch that I put in two "0"s and not just one.

Let me know,
Danny
0
BrianWrenCommented:
I have a teacher's mentality...

Currently, any chance I get, I teach people what the Bible says, how to operate computers, world history and logic (not exclusively restricted to programming logic!).

Brian
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.