Results 1 to 3 of 3
  1. #1
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104

    Using VBA to execute a [Windows Key] + choice

    Hi all,

    Am trying to get the Windows Shortcut combination {[Left Windows Key] + "L"} to work from a command button.


    Any ideas?

    I just want it to fire the Windows "Lock the Computer" option, so that the user has to enter their password to reopen the screen at another point in the form (the VBA code determines and executes that whilst the user is re-logging back on)

    thanks in anticipation
    Pete

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Open a new form, add a textbox. In the KeyDown Event for the textbox put the following code so it looks similar

    Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
    Debug.Print KeyCode
    Debug.Print Shift
    End Sub

    run your new form. place cursor in box and hit the Windows Key, the keycode should output into the immediate window of the compiler. (Ctrl + G)

  3. #3
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    Quote Originally Posted by DubCap01 View Post
    I just want it to fire the Windows "Lock the Computer" option, so that the user has to enter their password to reopen the screen at another point in the form (the VBA code determines and executes that whilst the user is re-logging back on)
    If that's the goal to accomplish, I suggest you to go the command line route to call the "lock function" as shown here.

    The code in vba is as simple as:

    Code:
    Shell "rundll32.exe user32.dll, LockWorkStation"
    Why to use Shell? Its much easier and more robust than using any variant of sending keystrokes.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. RunSQL vs. QueryDef.Execute vs. CurrentDB.Execute
    By caubetiep1337 in forum Queries
    Replies: 8
    Last Post: 12-16-2015, 05:35 PM
  2. Replies: 10
    Last Post: 02-27-2015, 11:28 AM
  3. Replies: 5
    Last Post: 06-25-2014, 09:19 AM
  4. Replies: 18
    Last Post: 10-21-2013, 05:13 PM
  5. Replies: 3
    Last Post: 07-15-2010, 05:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums