Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    KeyDown - Again (A2K)

    I swear I
    Cheers,
    Andy

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: KeyDown - Again (A2K)

    Does:
    <pre>Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Shift = acShiftMask And KeyCode = vbKeyF10 Then
    DoCmd.Close
    End If
    End Sub
    </pre>

    work for you?

    If you look in the Object Browser under Globals, you will find a whole list of vbKeyXXX constants. Note: the vbKeyShift etc constants are not the ones to use for the Shift argument of this event.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: KeyDown - Again (A2K)

    Rory,

    Thanks for the quick reply:

    This is the code as it exists at the moment including your suggested change:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF10 Then
    DoCmd.GoToRecord , , acNewRec
    KeyCode = 0
    End If

    If Shift = acShiftMask And KeyCode = vbKeyF10 Then
    DoCmd.Close
    End If
    End Sub

    Unfortunately these two fellas don't play well together, because using either the F10 or Shift-F10 throws me into New Record Mode.
    Cheers,
    Andy

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

    Re: KeyDown - Again (A2K)

    That is because you check first whether F10 has been pressed, whether in combination with Shift or not. You should change the logic of your If statements:

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    ' Did the user press F10?
    If KeyCode = vbKeyF10 Then
    ' If so, did the user hold down the Shift key?
    If Shift = acShiftMask Then
    ' If so, close the form
    DoCmd.Close
    Else
    ' Else create a new record
    DoCmd.GoToRecord , , acNewRec
    End If
    ' Cancel further processing of the keystroke
    KeyCode = 0
    End If
    End Sub

  5. #5
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Toronto Canada
    Posts
    920
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: KeyDown - Again (A2K)

    Hans, Hans, Hans,

    You are just the little Easter Bunny of the Access Coding world. As always, thanks most kindly to both yourself and to Rory for pointing to the Globals,
    Cheers,
    Andy

Posting Permissions

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