473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Caps Lock as a Default

114 100+
Hello,

I would like to have all data entered into every form in my database in all capital letters as a default. Is there a way to go about this?

martin DH
Feb 27 '07 #1
17 11442
Rabbit
12,516 Expert Mod 8TB
Sorry, don't know of a way to do this. I'm wondering if maybe you could retreive the status of the Caps Lock and send it if it's not on. But again, I don't know how to do this. Maybe someone else will be able to help. But I suppose you could have a checkbox that turns on and off whether or not the control capitalizes the string in the After Update event.
Feb 28 '07 #2
NeoPa
32,556 Expert Mod 16PB
KeyPress Event
The KeyPress event occurs when the user presses and releases a key or key combination that corresponds to an ANSI code while a form or control has the focus. This event also occurs if you send an ANSI keystroke to a form or control by using the SendKeys action in a macro or the SendKeys statement in Visual Basic.

Private Sub object_KeyPress(KeyAscii As Integer)
Object "Form" or the name of a control on a Form.

KeyAscii Returns a numeric ANSI key code. The KeyAscii argument is passed by reference; changing it sends a different character to the object. Setting the KeyAscii argument to 0 cancels the keystroke so that the object doesn't recognize that a key was pressed.
You can set this up for every form in your database. It's a little laborious maybe, but I'm not aware of any other way of doing it.
Feb 28 '07 #3
ADezii
8,834 Expert 8TB
Hello,

I would like to have all data entered into every form in my database in all capital letters as a default. Is there a way to go about this?

martin DH
Don't think it can be done, but what you can do is force all lower case letters to be automatically entered as UPPERCASE in your Text Boxes as you type by copying this code into the KeyPress() Event of every Text Box on every Form. Other Control Types may have to be handled differently. As NeoPa stated, it would be just a little laborious but not ridiculous.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtCourse_KeyPress(KeyAscii As Integer)
  2.   If KeyAscii >= 97 And KeyAscii <= 122 Then      'lowercase a to z
  3.       KeyAscii = (KeyAscii - 32)
  4.   End If
  5. End Sub
Mar 1 '07 #4
NeoPa
32,556 Expert Mod 16PB
500 posts ADezii - Nice going :)
As to your suggestion, would it not be a better idea to handle it at the form level?
StartEdit:
As ADezii has pointed out later in this thread, you would need to set the KeyPreview property of the form to Yes for this to work correctly.
EndEdit:

At worst then, you may need a Select Case statement to avoid some controls but I can't think of any situations where even that would be required.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2.   Select Case Chr(KeyAscii)
  3.   Case "a" To "z"
  4.     KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
  5.   End Select
  6. End Sub
This will involve fewer procedures, and be less laborious overall.
Mar 1 '07 #5
ADezii
8,834 Expert 8TB
500 posts ADezii - Nice going :)
As to your suggestion, would it not be a better idea to handle it at the form level?
At worst then, you may need a Select Case statement to avoid some controls but I can't think of any situations where even that would be required.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyPress(KeyAscii As Integer)
  2.   Select Case Chr(KeyAscii)
  3.   Case "a" To "z"
  4.     KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
  5.   End Select
  6. End Sub
This will involve fewer procedures, and be less laborious overall.
NeoPa:
Thanks for the 500 Post compliment. You're right, it would work much better at the Form Level, but don't forget that you would have to set the Form's KeyView Property to Yes.
Expand|Select|Wrap|Line Numbers
  1. Why not eliminate 2 Function Calls?
  2. KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
  3. KeyAscii = KeyAscii - 32
Mar 1 '07 #6
NeoPa
32,556 Expert Mod 16PB
NeoPa:
Thanks for the 500 Post compliment. You're right, it would work much better at the Form Level, but don't forget that you would have to set the Form's KeyView Property to Yes.
I forgot that a long time ago. I seem to recall that I did once need to use this and I suppose I must have known about or discovered the KeyPreview property then.
Expand|Select|Wrap|Line Numbers
  1. Why not eliminate 2 Function Calls?
  2. KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
  3. KeyAscii = KeyAscii - 32
Because the benefit of the code showing clearly what it's doing outweighs the (in this case negligible) processing overhead. I considered the context, which is operator related, and I couldn't see any benefit in code efficiency here (It only gets run once per keystroke - I don't think even my wife could keep it busy enough :D).
Mar 1 '07 #7
NeoPa
32,556 Expert Mod 16PB
BTW You and I could both look at 32 in this context and immediately understand what it's referring to. Not everyone would find it that straightforward.
I did look at defining a constant for the value but it refused to evaluate a function in a constant declaration (as I suspected it would) so I had to revert to using the functions in the code.
Mar 1 '07 #8
martin DH
114 100+
BTW You and I could both look at 32 in this context and immediately understand what it's referring to. Not everyone would find it that straightforward.
I did look at defining a constant for the value but it refused to evaluate a function in a constant declaration (as I suspected it would) so I had to revert to using the functions in the code.

Thanks for your help! Martin DH
Mar 8 '07 #9
missinglinq
3,532 Expert 2GB
I also have my DBs set up to accept caps only. Here's the easy way to do it!

In a new module place this code:

Expand|Select|Wrap|Line Numbers
  1. 'Windows API/Global Declarations for :CapLock
  2. '*********************************************
  3. Public Const VK_CAPLOCK = &H14
  4.  
  5. Public Type KeyboardBytes
  6. kbByte(0 To 255) As Byte
  7. End Type
  8. Public kbArray As KeyboardBytes
  9.  
  10. Public Declare Function GetKeyState Lib "user32" _
  11. (ByVal nVirtKey As Long) As Long
  12. Public Declare Function GetKeyboardState Lib "user32" _
  13. (kbArray As KeyboardBytes) As Long
  14. Public Declare Function SetKeyboardState Lib "user32" _
  15. (kbArray As KeyboardBytes) As Long
When prompted name the module ControlCapsLock

In the On_Load sub of the first form in your db that is used place this code:

Expand|Select|Wrap|Line Numbers
  1. 'Turn Capslock On
  2. GetKeyboardState kbArray
  3. kbArray.kbByte(VK_CAPLOCK) = 1
  4. SetKeyboardState kbArray
Then, in the last form you use before before unloading the application:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Unload(Cancel As Integer)
  2.  
  3. 'Turn Capslock OFF
  4. GetKeyboardState kbArray
  5. kbArray.kbByte(VK_CAPLOCK) = 0
  6. SetKeyboardState kbArray
  7. End Sub 
If you should have a field, like a memo field, where you don't want all caps, simply use the CapsLock Off code in the GotFocus event for the field, then the CapsLock On code in the LostFocus event for the field to reset it.
Mar 8 '07 #10
NeoPa
32,556 Expert Mod 16PB
I also have my DBs set up to accept caps only. Here's the easy way to do it!
I'm not sure I'd describe that as the easy way Linq.
It's certainly another way, though the side-effect of forcing CAPS-LOCK on for other applications while your database is open would deter me somewhat.
We have an application at work (Not Access related at all) which has a similar effect and, as I frequently switch between running tasks, I find it a nuisance.
Mar 9 '07 #11
missinglinq
3,532 Expert 2GB
I think it beats all the other methods mentioned here if 1) you want all caps for all entries in a given database (as the poster here specified) and 2) you have many forms/controls involved. I think we have to remember that while many of us here are power users, the vast majority of people who use computers aren't, but rather are users who work on one application at a time.I think the same thing applies when it comes to shortcuts and "standard" methods of doing things in Access. Our knowledgebase of Access is not the as that of a customer service rep or a healtcare worker that's using an Access database.
Mar 9 '07 #12
NeoPa
32,556 Expert Mod 16PB
I suppose we'll just have to hold different opinions on that one then ;)
I'm not good at predicting what other people find complicated though. The good thing about these forums is that the OP can choose from any of the options here. I know which one I'd choose, but then I'm heavily biased :D
Mar 9 '07 #13
missinglinq
3,532 Expert 2GB
No, you biased? LOL! ;0)>
Mar 9 '07 #14
martin DH
114 100+
Thanks for your suggestion, Linq. Although, as neopa thought, this database is being used in the midst of several applications and the suggestions posted before seem to be doing the job well. Thanks though!

Martin DH
Mar 20 '07 #15
kkc97
1
Hello,

I would like to have all data entered into every form in my database in all capital letters as a default. Is there a way to go about this?

martin DH
In design view of each form, go to properties of the text boxes and format them with ">"
Dec 6 '07 #16
Jim Doherty
897 Expert 512MB
Hello,

I would like to have all data entered into every form in my database in all capital letters as a default. Is there a way to go about this?

martin DH
To add to the veritable sweetshop of code that is this thread, heres another little snippet that you can place in the onkeypress event of a particular textbox you might wish to force to uppercase.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim Character
  3.     Character = Chr(KeyAscii)
  4.     KeyAscii = Asc(UCase(Character))
  5.  
Jim :)
Dec 7 '07 #17
sdimov
1
Use UCASE if you use SQL statements or place a UCASE convert function on the after update event.
Jan 18 '08 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Robert | last post by:
Hi! I was wondering if the was any way to determine the state of the caps lock key, on or off. Of course I can capture the key events and see whether the caps lock is pressed, but that does not...
4
by: Peter D | last post by:
I have a second hand bar code reader (keyboard wedge) en i can read the bar codes but after every scan he turns my caps lock on. (GRRRRRR). I search a code to turn my caps lock off or can anyone...
3
by: Mike L | last post by:
How do I turn Caps Lock on, when my form opens?
2
by: GSX | last post by:
Would somebody be able to point me in the direction of figuring out how to determine if Caps Lock is on, Num Lock is on, INS or OVR, etc.? I'm looking to display their status in a statusbar, but...
0
by: fNew VBer | last post by:
Hi. I'm new to Visual Basic .NET, so you'll have to bear with me . . . I want to create an app that turns off CAPS LOCK when the SHIFT key is pressed. I got the code to turn off CAPS LOCK to...
1
by: yxq | last post by:
Hello, I have a main form, there other some controls(i.e. textbox) in the form. I want to detect whether Caps Lock key is pressed in form-key event. Private Sub Form1_KeyUp(ByVal sender As...
1
by: charlies224 | last post by:
Hi, I am writting a software that requires me to make sure the Num Lock is always on and Caps Lock is always off. First, I know how to detect if Num Lock or Caps Lock is on or off (if...
1
by: Brian Parker | last post by:
I play a DirectX game and while that game is running, I would like to change the behavior of the Caps Lock key. When it's pressed, I don't want it to toggle my Caps Lock on and off, but instead...
4
by: zacks | last post by:
I'm not sure when it came into being, since this it the first time I have worked very much with a password control in .NET, but if a textbox that has a non-empty value for PasswordChar or the...
1
by: cmrhema | last post by:
Hi, Two questions 1. In windows application if we put on the below code, it will identify whether caps lock is on or not if (TextBox.IsKeyLocked(Keys.CapsLock)) { ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.