Capitalize Every Field

LQ

Registered User.
Local time
Today, 19:40
Joined
Apr 5, 2001
Messages
145
This seems like it should be so easy, but I can't get it to work! I know that it is not good practice to use the same bit of code over and over in a form, and that I should instead write a function and call it. I want every field in a form to be capitalized. I have been using

me.activecontrol=ucase(me.activecontrol)

This works, but I can't for the life of me figure out the correct syntax to write the function instead of using this code behind each and every control on my form.

Thanks for any pointers!!!
 
You can just put the greater than symbol into the Format property of the field: >

D.J.





[This message has been edited by DJBummy (edited 08-27-2001).]
 
Thanks for the suggestion, DJ Bummy, but I actually want the data itself converted to uppercase as opposed to having it viewed (formatted)that way.

LQ
 
Thanks again, DJ, but I am still not sure how to proceed. I guess I am not writing the function correctly, or not calling it correctly, because when I try to call the function from within the form, I am getting an error that says I entered a function name that Access can't find.

I guess if I can't figure it out, I can just repeat the code throughout my form, but I hate to do something like that *knowing* it's the wrong thing to do!
 
Not to pressure anyone, BUT...

I still can't solve this puzzle. I would greatly appreciate it if anyone could help me figure out this function so I don't have to resort to the messiness of putting the same code behind each and every one of my controls.

Thanks!
 
if you put this code behind a command button on your form, this should do the trick....


Dim ctl As Control

For Each ctl In Controls
If ctl.ControlType = acTextBox Then
ctl.Value = UCase(ctl.Value)
End If
Next ctl

This will loop through each control and capitalize the record if it is a text box... hope this helps.

Doug
 
Thank you for the suggestion, Doug!!! It looks like what I need....*except*....I can't get it to work! I am getting an error that says "Run time error 2448. You can't assign a value to this object". The line it's stopping on is

ctl.Value = UCase(ctl.Value)

Also, can I put it in the form's Before Update or After Update event instead of behind a command button?

Thanks again!
 
Hi LQ. In my opinion there’s nothing wrong with the way you’re currently doing it. But, if you’d like to eliminate the code behind each control then this might do the trick. Place this code in the forms On Current and Before Update events. Then, whenever you exit a record whose data has changed or enter a record, the code will itinerate through each control on the form. If the control is a textbox then it capitalizes it. Hope it helps.

Code:
Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
    If ctl.ControlType = acTextBox Then ctl = UCase(Nz(ctl))
Next ctl

~Abby

P.S.
Sorry for the duplication. I typed this out but forgot to submit it before going to lunch. When I got back I simply hit submit, so never saw Doug's reply. But, I've decided to leave this up in case it turns out to be useful.

[This message has been edited by Abby N (edited 08-28-2001).]
 
Thanks Abby and D Fresh...

You have solved my dilemma! I ended up using Abby's code in my form's before update event, and it seems to work!!

A very grateful LQ
 
why not try the > in the format field in the design view of your table rather than on the form ?
 
Hello Oldsoftboss,
As was posted in an earlier reply, using the ">" at form level or at table level will only show the entry as "upper case" only at that level. Even if you use it directly in the table, then the data will appear as "upper case" in the table view, but it will actually be stored "as entered".

HTH
RDH

[This message has been edited by R. Hicks (edited 10-28-2001).]
 
Try this, will make for less code:

Private Function CVUpp(KeyAsc As Integer) As Integer
CVUpp = Asc(UCase(Chr(KeyAsc)))
End Function

Private Sub Form_KeyPress(KeyAscii As Integer)
KeyAscii = CVUpp(KeyAscii)
End Sub

This looks better because it catches lowercase letters when they are entered and converts them up so the user literally CANNOT enter a lowercase letter

Don't forget to set the Forms KeyPreview property to yes so the form see's the ascii code before the control.

HTH

Ian
 

Users who are viewing this thread

Back
Top Bottom