Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Check for Up or Down arrow.

If KeyCode = vbKeyF4 And Shift = 1 Then
    If MsgBox("Are you sure you want to leave?", vbOKCancel) = vbOK Then
    Unload Me
    Else
    Form1.Show
End If
End If
End Sub

    Source: geocities.com/matkins70