Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    It's so frustrating when you start filling in a field in an Access form such as GIVEN NAME and you start typing something like this: bRIAN (instead of Brian). Is there some piece of code that detects when the CAPSLOCK is set the wrong way around and automatically reverses it? ie if the first letter in the field is always a capital and you start with lowercase it switches the capslock on the keyboard before continuing onto the next letter?

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    I don't know of anything specific to Access or VBA - keyboard stuff is pretty low level. But I do like one particular piece of <img src=/S/free.gif border=0 alt=free width=30 height=15>ware called FirstCap 3.2. I don't have a need for it now because i dON'T MAKE tHOSE KINDS oF mISTAKES. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> You can find it under Products on the FalsinSoft Home Page.

    That said, there is the "change case" command in word (Shift+F3, but I can't find it on the <img src=/w3timages/censored.gif alt=censored border=0> menus) that will toggle the case of the selection through lower, upper and proper. For instance, if the word bRIAN is selected in the line:
    My name is bRIAN.

    then successive Shift+F3 presses will give:
    My name is brian.
    My name is Brian.
    My name is BRIAN.

    Maybe it's possible to hook this functionality for your purposes, but I wouldn't know where to start on that one. There's also the star<post#=433911>post 433911</post#> from MarkD on Converting Text to Proper Case, which may be of use in this context.

    Alan

  3. #3
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    As an alternative, you can use the Control panel, Accessability options. There's an option to let you hear a beep every time you hit the Caps/Scroll/Num-Lock keys, thus alerting you that you touched the Caps key unvoluntarily again. This works for me.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    There is an AutoCorrect setting for "Correct accidental use of cAPS LOCK". I don't know if you can set it directly in Access 2000, but you certainly can in Word. It's an Office-wide setting, so turning it on in Word will turn in on in Access too.

  5. #5
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    In Access you could always attach code to the text box's afterupdate event using the strconv function to set the text how you want. That would achieve the same result wouldn't it?

    Example:

    <pre>On Error Resume Next
    Dim strName As String
    If IsNull(Me.txtFName) Then
    Exit Sub '---->
    Else
    strName = Me.txtFName.Text
    Me.txtFName = StrConv(strName, vbProperCase)
    End If
    </pre>


    Just a thought.
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    Thanks, I thought of something like that but you would need to attach this code to each text box on the form. What I was hoping was a routine in the first textbox that is triggered by the afterupdate event to invoke some code like this Windows Scripting code:
    set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys "{CAPSLOCK}"
    and this would actually toggle the keyboard so further coding woud not be necessary.
    Is there a way of determing in code if a letter is in upper or lower case - like a property of the letter?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    1. You don't need to create a WScript.Shell object in order to use SendKeys. SendKeys is part of standard VBA.
    2. Each character has a numeric code; you can use the Asc (short for ASCII) function to get this code. Upper case letters are in the range 65 to 90 inclusive.
    3. If you turn off Caps Lock in the first text box on a form, the user can still accidentally hit it instead of Shift in another text box.

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    tHANKS hANS - SEE IT HAS happened again!
    Re point 3. - I realise this but it is much, much more common to have deliberately turned the caps lock on for some reason previous to entering the form and only noticing it when the field starts to fill in like the beginning of this message. The code I seek would instantly correct this error. It's a small thing but it had driven me nuts for years.
    I came up with this piece of code that you can attach to the open event of the form: it would work fine if the SendKeys statement functioned in VBA as it does in WSript - but it doesn't function.
    My question is why? Is there somet application that needs activating ?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    Cutting out all the unneeded ballast, this works for me:

    Private Declare Function GetKeyState Lib "user32" _
    (ByVal vKey As Long) As Integer

    Private Sub Form_Open(Cancel As Integer)
    If GetKeyState(vbKeyCapital) And 1 Then
    SendKeys "{CAPSLOCK}"
    End If
    End Sub

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    Yes, much cleaner (I just modified some code I found for the purpose without bothering to cut it down).
    However, my problem is not solved as the SENDKEYS "{CAPSLOCK}" line just makes all the little green
    lights on the keyboard blink but none of them change state - including the CAPS LOCK.
    But the original code
    set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys "{CAPSLOCK}"
    works fine.
    What could this be?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    I can't explain that - as I wrote, SendKeys "{CAPSLOCK}" (without creating a WScript.Shell object) works for me. Hmm, do you happen to have a procedure or function called SendKeys?

  12. #12
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    No. And this sample from the VBA help files works perfectly:
    Public Sub SK()
    Dim ReturnValue, I
    ReturnValue = Shell("CALC.EXE", 1) ' Run Calculator.
    AppActivate ReturnValue ' Activate the Calculator.
    For I = 1 To 100 ' Set up counting loop.
    SendKeys I & "{+}", True ' Send keystrokes to Calculator
    Next I ' to add each value of I.
    SendKeys "=", True ' Get grand total.
    SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
    End Sub

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    There are several newsgroup posts about SendKeys not toggling Caps Lock correctly in Access. You can find a longish replacement in API: Replacement for Sendkeys, but you might as well use the workaround you already have.

  14. #14
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    Thanks Hans,
    But what workaround - Windows Scripting host?
    Not sure how in put this code into VBA...

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Toggle CAPSLOCK automatically (Office 2000 SP 1A WinXP)

    You wrote
    <hr>But the original code
    set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys "{CAPSLOCK}"
    works fine.<hr>
    I thought you had tested it in Access, but am I to understand you didn't? It is valid VBA.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •