VBA – Determine if the Caps Lock button is enabled on Password entry

Patrick Roth - Click for blog homepageWith password policies in place in Dynamics 10.0 RTM, it was easy to be able for your user to ‘lock themselves out’ after a mistyped password or two. 

Because Dynamics GP doesn’t give you any kind of warning that the Caps Lock key is enabled, the user wouldn’t necessarily notice this is the real issue and not a typo and all of a sudden you are locked out. 

With 10.0 SP2 and the change on how Dexterity/GP tries to login; this is less of a challenge but it still is possible for the user to lock themselves out of Dynamics GP because they left the Caps Lock key on. 

To solve this, I wrote some VBA code that works on the Login window in Dynamics GP.  It is somewhat advanced in that it uses the Win32 API to get the status of the keyboard buffer and then specifically checks to see if the Caps Lock key is enabled or not.  If it is, a message box warns the user that has happened and suggests turning it off.  It would be a lot cooler to get a balloontip to point to the password field (as Windows does) but I’m not sure that is possible in VBA and while pretty to see, it doesn’t give any advantages to just using a simple message box.

In the code sample below, both the Win32 API declaration and the VBA code is shown for this project.  The package file that I created for my 10.0 installation is also attached to this post.  I didn’t test this on other Dynamics GP versions but I would suspect that it should work at least back to 8.0.  This code should also work on any password (or otherwise) field that you choose to add it to with just minor tweaks.

Login Window Code Example

Developer Support

// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)


Comments (6)

  1. Abbas says:

    Dear Patrick,

    What’s your email address????



  2. David Musgrave says:

    Hi Abbas

    We don’t normally post our email addresses publically as this encourages them to be picked up and used by spammers.

    If you have a question relating to this blog post you can ask it here as a comment.

    If you have a comment regarding the blog in general, use the Blog Feedback? – Contact Us link at the top of the blog.

    For a support issue, you can post to the newsgroups or log a support incident.

    Patrick and I both monitor the newsgroups and so will respond there as well.



  3. Jovy says:

    I’m not a programmer please give some guide on how to add this script thanks.

  4. Perry Smith says:


    Download the attached zip file.  Import the package using Customization Maintenance.


    Thanks!  Great peice of code to include on my installs.

    Perry Smith

  5. Larry Carrethers says:

    I installed the package and log out of gp and back in. I turned on caps but it doesn’t tell me caps is on. is there something special I have to do?

    1. Hi Larry

      Please note that the more recent versions of Dynamics GP have this warning built in.