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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling the Escape Key globally

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
US
I would like to disable the Escape Key globally, that means in forms and reports. I would like it to call the On Undo Event in case there was a change, otherwise it should not do anything. My experience is that if I hit the Escape key when the report closes, it interferes with the processes running.

I know that I can set in the KeyDown Event procedure the keycode = 0, but how can I stop the escape key in reports, and have a public function called whenever the escape key is pressed.

This is my code in a form what do I do in a report?

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
 
I've tried this and it seems to work ok:

The public function in a module:
Code:
Public Sub UndoRec_Click()

  'For some reason this has to be done at least twice - the wonders of Access!!!
  For a = 1 To 2
    Reports!table1.RecordSource = "SELECT * FROM Table1 WHERE asdfas >= #01/01/1900#"
    Reports!table1.Requery
  Next a

End Sub

and the code in the report is the same as in your form:
Code:
Private Sub Report_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo Err_Report_KeyDown

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

Err_Report_KeyDown:
    MsgBox Err.Description
    Resume Exit_Report_KeyDown

End Sub

Initially the report has two records, after pressing escape while the report is open it then only has one record.
 
I tried using your code and its not calling it. For testing purposes I put this piece of code in to see if Event Procedures not listed in the report properties run. It did not work.

Code:
Private Sub Report_Load()
    
    Me.KeyPreview = True

End Sub

I inserted a breakpoint and it did not call it. I think its because there is no On Load Property. How did you invoke these procedures when they are not listed?
 
I tried putting it into the Report_Open Procedure

Code:
Private Sub Report_Open(Cancel As Integer)

    Me.KeyPreview = True

End Sub

I got this error:
Complie Error: Method or Data Member not found

How did you get these procedures to work?
 
Sorry, but for me, a Report has NO KeyXyz event/property.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, I appreciate your response.

So is there a way to disable the {ESC} Key? Its basically when I close the report and it goes back to the form and calls Me.Requery, if the {ESC} key was hit it gives me object invalid.

this is the code where I have the problem:
Code:
Private Sub Terms_GotFocus()

    If Nz(Me.Status.Tag, 0) = 1 Then
        If Me.RecordsetClone.RecordCount > 0 Then
            [COLOR=red]Me.Requery[/color]
            Me.Status.Tag = 0
        End If
    End If

End Sub
 
Why not use an error handler procedure ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I changed the code with the Error Handler
Code:
Private Sub Terms_GotFocus()
On Error GoTo Err_Terms_GotFocus

    If Nz(Me.Status.Tag, 0) = 1 Then
        If Me.RecordsetClone.RecordCount > 0 Then
            Me.Requery
            Me.Status.Tag = 0
        End If
    End If

Exit_Terms_GotFocus:
    Exit Sub

Err_Terms_GotFocus:
    MsgBox Err.Description
    Resume Exit_Terms_GotFocus

End Sub

What seems to be happening is since its not stopping anywhere in my code, that the {ESC} Key unapplies the recordsource that was suppose to be set for the form, and all fields get the "?Name" in it. How do I stop this from happening, that from when the Report closes till the Recordsource is set (basically till all the code passed), not to allow keystrokes or at least to disable the {ESC} key. Is there something that is the opposite from "DoEvent" that gives full control to the code, and does not allow anything else to interfere?
 
The code I posted was written and tested in Access 2007, so maybe (I can't remember - I've not used Access seriously since Access 97) these Events aren't available in the earlier versions. I can assure you that the code does work in 2007.
 

Sorry, but for me, a Report has NO KeyXyz event/property

Maybe a new thing in 2007? Never had command buttons in reports before, but I understand they do in Version 2007.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top