Results 1 to 9 of 9
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoKeys Macro (A2000)

    I,m trying to disable the Left Arrow & Right Arrow keys by using the cancel event property in an AutoKey Macro.
    When I save the macro, I get a message saying the syntax or key combination is not allowed.

    I'm using {VbKeyLeft} as the syntax. Does anyone know either the correct way to do this.

    Dave

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoKeys Macro (A2000)

    You can't use constants in macros. You have to use their numeric equivalent, which can be determined by looking them up in the object browser.
    Charlotte

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

    Re: AutoKeys Macro (A2000)

    Dave,

    You can't reassign arrow keys in a macro. According to Access (97) help, the keys you can reassign are:

    Ctrl+letter
    Ctrl+digit
    Function keys Fn
    Ctrl+Fn
    Shift+Fn
    Ins
    Ctrl+Ins
    Shift+Ins
    Del
    Ctrl+Del
    Shift+Del

    Besides, it wouldn't be a very good idea to cancel an arrow key in AutoKeys: it would mean that the keys would be disabled whatever you were doing in the database.

    'What you *can* do is disable them in a form. Set the KeyPreview property of the form to Yes/True, and create an event handler for the KeyDown event. Replace unwanted key codes by 0.

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyLeft, vbKeyRight
    KeyCode = 0
    ' Case ...
    ' ...
    End Select
    End Sub

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoKeys Macro (A2000)

    I notice Hans you use "select Case", maybe I need to do the same with my code:

    Private Sub cmbClientCode_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDown Then Me.CmbRegistration.SetFocus
    If KeyCode = vbKeyUp Then Me.cmbInsurerCode.SetFocus
    If KeyCode = vbKeyF11 Then
    If Me.cmbClientCode.ListIndex > 0 Then
    Me!cmbClientCode.ListIndex = Me!cmbClientCode.ListIndex - 1
    End If
    End If
    If KeyCode = vbKeyF12 Then
    If Me.cmbClientCode.ListIndex < Me.cmbClientCode.ListCount - 1 Then
    Me!cmbClientCode.ListIndex = Me!cmbClientCode.ListIndex + 1
    End If
    End If
    If KeyCode = vbKeyF2 Then Call cmbClientCode_DblClick(1)
    End Sub

    I use quite a few KeyCode combinations, can you steer me in the right direction here. I needed to use the VbKeyRight & Left to replace the F11 & F12 parts of the code, but when I do, I get odd happenings.
    I assume the Access default action for the keys is kicking in at the same time as I call them through code.

    Dave

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

    Re: AutoKeys Macro (A2000)

    Dave,

    Using "Select Case" will certainly make your code more readable.

    There are several keystrokes that Access will handle automatically (arrow keys, tab key, function keys), unless you cancel them by setting the KeyCode to 0 after you have done your own processing.

    For example:

    Private Sub cmbClientCode_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyDown
    Me.CmbRegistration.SetFocus
    KeyCode = 0
    Case vbKeyUp
    Me.cmbInsurerCode.SetFocus
    KeyCode = 0
    Case vbKeyF11
    If Me.cmbClientCode.ListIndex > 0 Then
    Me!cmbClientCode.ListIndex = Me!cmbClientCode.ListIndex - 1
    KeyCode = 0
    End If
    Case vbKeyF12
    If Me.cmbClientCode.ListIndex < Me.cmbClientCode.ListCount - 1 Then
    Me!cmbClientCode.ListIndex = Me!cmbClientCode.ListIndex + 1
    KeyCode = 0
    End If
    Case vbKeyF2
    Call cmbClientCode_DblClick(1)
    KeyCode = 0
    End Select
    End Sub

  6. #6
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoKeys Macro (A2000)

    Thanks again Hans.

    This makes things much clearer, ( Have a lot of editing to do noe.)

    Dave

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoKeys Macro (A2000)

    Sorry to be a pain, one final thing.
    If I want to use lets say VbKeyF3 to do more than one task on the same form.
    Which is the correct way, Example 1 or Example 2
    (Example 1)
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    On Error GoTo ERRTRAP
    Select Case KeyCode
    Case vbKeyF5
    Call Command19_Click
    KeyCode = 0
    Case vbKeyF3
    Me.sbfLabourBooking.SetFocus
    KeyCode = 0
    Case vbKeyF3
    DoCmd.GoToRecord , , acNewRec
    KeyCode = 0
    Case vbKeyF3
    Me.EstimateNo = Forms!frmlabourbooking!txtSearchEstimateNo.Value
    KeyCode = 0
    Case vbKeyF3
    Me.supp = Forms!frmlabourbooking!txtSearchSupp.Value
    KeyCode = 0
    End Select
    Exit Sub
    ERRTRAP:
    End Sub

    (Example 2)
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    On Error GoTo ERRTRAP
    Select Case KeyCode
    Case vbKeyF5
    Call Command19_Click
    KeyCode = 0
    Case vbKeyF3
    Me.sbfLabourBooking.SetFocus
    DoCmd.GoToRecord , , acNewRec
    Me.EstimateNo = Forms!frmlabourbooking!txtSearchEstimateNo.Value
    Me.supp = Forms!frmlabourbooking!txtSearchSupp.Value
    KeyCode = 0
    End Select
    Exit Sub
    ERRTRAP:
    End Sub

    thanks again
    Dave

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoKeys Macro (A2000)

    Only the first case will ever be executed if you put it in twice, so the second example is the only way it will every work. However, I would suggest that you cancel the keycode by setting it to 0 *before* you do any of the other stuff in the case. Otherwise, it might bite you.
    Charlotte

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AutoKeys Macro (A2000)

    Thanks all, I can take it from here.

    Dave

Posting Permissions

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