Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The difference between the {ESC} Key and the Undo Command

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
0
0
US
I need help understanding the difference between hitting the {ESC} Key and the "Me.Undo" Command. As written previously, when I hit the "{ESC}" key it gives me an "Object invalid or no longer set", however when I click on the undo command button things work fine and the error does not pop up.

I was trying to capture the "{ESC}" key in the KeyDown Event procedure and send it to the Undo Command but it gives me that error again.

Please! if you can enlighten me on whats happening I would really appreciate it. I am trying to debug this issue for 3 days, and have not figure it out yet.
 
I figured out a way how to capture the {ESC} Key

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Form_KeyDown

    If KeyCode = vbKeyEscape Then
        
        KeyCode = 0
        
        Call UndoRec_Click
    
    End If
    
Exit_Form_KeyDown:
    Exit Sub

Err_Form_KeyDown:
    MsgBox Err.Description
    Resume Exit_Form_KeyDown

End Sub

Code:
Private Sub UndoRec_Click()
On Error GoTo Err_UndoRec_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_UndoRec_Click:
    Exit Sub

Err_UndoRec_Click:
    If Err.Number <> 2046 Then
        MsgBox Err.Description
    End If
    Resume Exit_UndoRec_Click
    
End Sub

I see clearly that there sure is some difference between the undo command and {ESC}, and what can I do globaly that it does not stop the code i.e. a DoCmd.Requery.
 
Code:
Private Sub Report_Close()
    
    Dim PO

    If Nz(Right(Me.OpenArgs, 6), "") <> "POSmry" Then
      '  DoCmd.Echo False
            PO = Forms!POForm!PONum
            Forms!POForm.Requery
      '  DoCmd.Echo True
        Forms!POForm.RecordsetClone.FindFirst "[PONum] = " & Me![PONum]
        Forms!POForm.Bookmark = Forms!POForm.RecordsetClone.Bookmark
        Forms!POForm.SetFocus
        DoCmd.Maximize
    
    Else
        Forms!POSumryForm.Visible = True
        DoCmd.Restore
    End If
    
End Sub

If I hit the {ESC} Key at the point "Forms!POForm.Requery" it gives "Object invalid" how can I avoid that the {ESC} should not stop the code or make the Form invalid?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top