Results 1 to 9 of 9
  1. #1
    Yance is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    22

    Smile Disable ALT+TAB key using VBA

    Hi all...



    Anyone can help me how to disable the ALT+TAB key using VBA code in microsoft access? I can do it in VB6 using low-level keyboard hook WH_KEYBOARD_LL. But this code didn't run in access vba. Can we do that using VBA code?

    Thx

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sounds like you want to trap it at the Windows level. What is the WH_KEYBOARD_LL code?

  3. #3
    Yance is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    22

    Question Disable ALT+TAB key using VBA

    Quote Originally Posted by RuralGuy View Post
    Sounds like you want to trap it at the Windows level. What is the WH_KEYBOARD_LL code?

    No, i just trying to make the internet cafe billing aplication using Microsoft Access. Oh, WH_KEYBOARD_LL is a variable of low level keyboard in SetWindowsHookEx API function which i use in vb to disable combination Alt+Tab key. But how we do that in access VBA?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Probably very close to the way you do it in VB. Do you want to post the code you are using in VB?

  5. #5
    Yance is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    22

    Question Disable ALT+TAB key using VBA

    Here this code that i use in VB:

    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    Public Const HC_ACTION = 0
    Public Const WM_KEYDOWN = &H100
    Public Const WM_KEYUP = &H101
    Public Const WM_SYSKEYDOWN = &H104
    Public Const WM_SYSKEYUP = &H105
    Public Const VK_TAB = &H9
    Public Const VK_CONTROL = &H11
    Public Const VK_ESCAPE = &H1B
    Public Const VK_STARTKEY = &H5B


    Public Const WH_KEYBOARD_LL = 13
    Public Const LLKHF_ALTDOWN = &H20

    Public Type KBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    time As Long
    dwExtraInfo As Long
    End Type

    Dim p As KBDLLHOOKSTRUCT

    Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim fEatKeystroke As Boolean

    If (nCode = HC_ACTION) Then
    If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
    CopyMemory p, ByVal lParam, Len(p)
    fEatKeystroke = _
    ((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
    ((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
    ((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
    p.vkCode = VK_STARTKEY

    End If
    End If

    If fEatKeystroke Then
    LowLevelKeyboardProc = -1
    Else
    LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
    End If
    End Function

    and then in the event Form Load (OnLoad) i write this code below to disable the ALT+TAB key combinations:

    hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)

    The problem is on "App.hInstance", because there is no "App" object/variable on Access.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    <ALT> Tab switches to the next Windows Application right? Is that what you are trying to stop?

  7. #7
    Yance is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    22
    Yes, that is. Do you know how to do that with access vba

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Unfortunately no. It sounds like you are on the right track but just need the right code for Access. Good luck. Have you checked Google yet?

  9. #9
    Yance is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    22

    Question

    Quote Originally Posted by RuralGuy View Post
    Unfortunately no. It sounds like you are on the right track but just need the right code for Access. Good luck. Have you checked Google yet?
    Yeah, i just need to find the vb object (App/App.hInstace) that equal in access VBA. I'd checked google too but still not found the right code

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

Similar Threads

  1. disable/gray out fields
    By michaelpclisbee in forum Forms
    Replies: 2
    Last Post: 07-05-2009, 07:59 PM
  2. Replies: 5
    Last Post: 06-17-2009, 02:18 PM
  3. How to disable edit for combo boxes
    By access in forum Forms
    Replies: 3
    Last Post: 06-17-2009, 09:11 AM
  4. Replies: 1
    Last Post: 06-02-2009, 04:44 PM
  5. Can you disable design view?
    By nkenney in forum Forms
    Replies: 1
    Last Post: 04-23-2009, 05:08 AM

Tags for this Thread

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