Caps Lock as a Default

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • martin DH
    New Member
    • Feb 2007
    • 114

    #1

    Caps Lock as a Default

    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
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    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.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      Originally posted by Help
      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.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by martin DH
        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.
        Code:
        Private Sub txtCourse_KeyPress(KeyAscii As Integer)
          If KeyAscii >= 97 And KeyAscii <= 122 Then      'lowercase a to z
              KeyAscii = (KeyAscii - 32)
          End If
        End Sub

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          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.
          Code:
          Private Sub Form_KeyPress(KeyAscii As Integer)
            Select Case Chr(KeyAscii)
            Case "a" To "z"
              KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
            End Select
          End Sub
          This will involve fewer procedures, and be less laborious overall.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by NeoPa
            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.
            Code:
            Private Sub Form_KeyPress(KeyAscii As Integer)
              Select Case Chr(KeyAscii)
              Case "a" To "z"
                KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
              End Select
            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.
            Code:
            [B]Why not eliminate 2 Function Calls?[/B]
            KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
            KeyAscii = KeyAscii - 32
            Last edited by ADezii; Mar 1 '07, 12:34 PM. Reason: Add On info

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32669

              #7
              Originally posted by ADezii
              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.
              Originally posted by ADezii
              Code:
              [B]Why not eliminate 2 Function Calls?[/B]
              KeyAscii = KeyAscii - (Asc("a") - Asc("A"))
              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).

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                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.

                Comment

                • martin DH
                  New Member
                  • Feb 2007
                  • 114

                  #9
                  Originally posted by NeoPa
                  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

                  Comment

                  • missinglinq
                    Recognized Expert Specialist
                    • Nov 2006
                    • 3533

                    #10
                    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:

                    Code:
                    'Windows API/Global Declarations for :CapLock
                    '*********************************************
                    Public Const VK_CAPLOCK = &H14
                    
                    Public Type KeyboardBytes
                    kbByte(0 To 255) As Byte
                    End Type
                    Public kbArray As KeyboardBytes
                    	
                    Public Declare Function GetKeyState Lib "user32" _
                    (ByVal nVirtKey As Long) As Long
                    Public Declare Function GetKeyboardState Lib "user32" _
                    (kbArray As KeyboardBytes) As Long
                    Public Declare Function SetKeyboardState Lib "user32" _
                    (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:

                    Code:
                    'Turn Capslock On
                    GetKeyboardState kbArray
                    kbArray.kbByte(VK_CAPLOCK) = 1
                    SetKeyboardState kbArray
                    Then, in the last form you use before before unloading the application:

                    Code:
                    Private Sub Form_Unload(Cancel As Integer)
                    
                    'Turn Capslock OFF
                    GetKeyboardState kbArray
                    kbArray.kbByte(VK_CAPLOCK) = 0
                    SetKeyboardState kbArray
                    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.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32669

                      #11
                      Originally posted by missinglinq
                      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.

                      Comment

                      • missinglinq
                        Recognized Expert Specialist
                        • Nov 2006
                        • 3533

                        #12
                        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.

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32669

                          #13
                          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

                          Comment

                          • missinglinq
                            Recognized Expert Specialist
                            • Nov 2006
                            • 3533

                            #14
                            No, you biased? LOL! ;0)>

                            Comment

                            • martin DH
                              New Member
                              • Feb 2007
                              • 114

                              #15
                              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

                              Comment

                              Working...