Results 1 to 4 of 4
  1. #1
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727

    Disabling keys and hot keys

    I have the code below for the On Key Down event with the Key Preview property set to "yes". This works for pretty much everything except split forms. Does anyone know why and how to fix it? Is the keycodes for split forms different?

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

    'to activate statements below, set Key Preview property to "yes" for each form.
    'then paste this code to each form in the "On Key Down" event.



    If KeyCode = vbKeyF1 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF2 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF3 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF4 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF5 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF6 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF7 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF8 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF9 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF10 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF11 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyF12 Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyPageUp Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyPageDown Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyMenu Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyEnd Then
    KeyCode = 0
    End If

    If KeyCode = vbKeyHome Then
    KeyCode = 0
    End If

    '80=P, 83=S, 109=- on NumPad, 107=+ on NumPad, 187==/+ next to backspace, 189=-/_ next to =/+ key
    '65=A, 70=F, 71=G, 72=H, 74=J, 13=Enter, 90=Z, 186=;/:, 188=,/<, 190=./>
    If (Shift And acCtrlMask) And (KeyCode = 80 Or KeyCode = 83 Or KeyCode = 109 _
    Or KeyCode = 107 Or KeyCode = 187 Or KeyCode = 189 Or KeyCode = 65 Or KeyCode = 70 _
    Or KeyCode = 71 Or KeyCode = 72 Or KeyCode = 74 Or KeyCode = 13 Or KeyCode = 90 _
    Or KeyCode = 186 Or KeyCode = 188 Or KeyCode = 190) Then
    KeyCode = 0
    End If

    If (Shift And acAltMask) > 0 Then
    KeyCode = 0
    Shift = 0
    End If

    End Sub

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    You may try setting KeyPreview of the main form:

    Private Sub Form_Load()
    Me.KeyPreview = True
    End Sub

    HTH

  3. #3
    data808 is offline Noob
    Windows 8 Access 2007
    Join Date
    Aug 2012
    Posts
    727
    That did not work. Any other ideas. I'm having trouble with the hot key "ctrl + ," this goes into design view. I haven't tried all hot keys but the fact I found this, bothers me that there may be other hot keys that my code is not disabling. Again this is only happening in split forms. Regular forms and reports seem to be fine.

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Okay, one more try. Problem is with Access 2007. Anyway, I found this code by Joe Anderson, maybe it will help.
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'Shift Argument for the 7 combinations of Shift, Ctrl and Alt keys:
    '0 None
    '1 Shift Key
    '2 Ctrl Key
    '3 Shift + Ctrl Keys
    '4 Alt Key
    '5 Shift + Alt Keys
    '6 Ctrl + Alt Keys
    '7 Shift + Ctrl + Alt Keys
    '----------------------------------------

    If Shift = 4 And KeyCode = vbKeyReturn Then 'trap Alt+Enter which opens Form property sheet
    KeyCode = 0
    Exit Sub
    End If

    With Me
    If (Shift = 3 And KeyCode = vbKeyA) Then
    On Error Resume Next 'covers case where control is disabled
    .Parent.Parent.SetFocus
    .Parent.Parent.Form.txtSA.SetFocus
    Err.Clear
    Exit Sub
    End If

    If Shift = 3 And KeyCode = vbKeyS Then
    On Error Resume Next 'covers case where control is disabled
    KeyCode = 0
    .Parent.Parent.SetFocus
    .Parent.Parent.fsubAcctSts.SetFocus
    .Parent.Parent.fsubAcctSts.Form.txtDtRvwd.SetFocus
    Err.Clear
    Exit Sub
    End If

    If (Shift = 3 And KeyCode = vbKeyF) Then
    On Error Resume Next 'covers case where control is disabled
    .Parent.SetFocus
    .Parent.Form.txtFind.SetFocus
    Err.Clear
    Exit Sub
    End If

    If Shift = 7 And KeyCode = vbKeyX Then
    If .Parent.Parent.Dirty = True Then
    MsgBox "Please Save or Cancel the current edits before attempting to close this form.", 16, "Close Account Form"
    Exit Sub
    End If
    DoCmd.Close acForm, .Parent.Parent.Name
    Exit Sub
    End If

    If Shift = 4 And KeyCode = vbKeyM Then
    Call Me.Parent.mMinMax(sOp:="Toggle")
    Exit Sub
    End If
    End With

    Form_KeyDown_Exit:

    Err.Clear
    End Sub

    HTH... Besides this, I don't what else for you to try!

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

Similar Threads

  1. Same Items Different Keys?
    By anonymust in forum Database Design
    Replies: 8
    Last Post: 12-16-2013, 04:53 PM
  2. Using keys from one table to another
    By Bubbadubya in forum Access
    Replies: 1
    Last Post: 03-21-2013, 01:50 PM
  3. Registry keys
    By ashu.doc in forum Access
    Replies: 1
    Last Post: 10-27-2012, 12:19 AM
  4. question about keys
    By johny in forum Access
    Replies: 3
    Last Post: 03-24-2012, 06:57 AM
  5. Tab or Enter keys
    By rwatkins in forum Forms
    Replies: 3
    Last Post: 05-11-2011, 03:22 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