Access 2007 Use Esc Key to Close Report

hangbill

Registered User.
Local time
Today, 02:01
Joined
Oct 30, 2009
Messages
14
Hi In 2003 this functionality worked fine, but not in 2007. Want to close a report by using Esc key. In 2007 can get it to partially work by making report modal. So I double click a form control and the report opens. Then press Esc and report closes. But if I use the magnifier to enlarge the report, then click the magnifier again to reduce the size, the Ecs key does not fire. I first have to click somewhere outside the report then Esc works; only one extra click I know but I'd really like it to work like it used to in 2003. Then thought I'd do an On key Down event but get error 2585, "action cant be carried out while processing a form or report" Private Sub Report_KeyDown(KeyCode As Integer, Shift As Integer) 'trying to close the report with Esc If KeyCode = 27 Then DoCmd.Close acReport, "IndividualReportsNoParams" End If End Sub Any ideas how to get this functionality working Thank you
 
Sorry for the formatting, I did use paras but seems not working
 
1. Drop a button in the Header section of your form
2. Set the Transparent property (in the Format tab) to Yes, set the Cancel property (in the Other tab) to Yes.
3. In the Click event of the button, put this code to close the form:
Code:
DoCmd.Close acForm, Me.Name
You don't need to change the code.
 
Hang on, this is for a report isn't it!:o What I explained in my previous post should work if the report is in Report View.

With your current method, ensure that the Key Preview property is set to Yes and try using the Key Press event instead.
 
Thanks for trying to help. Have tried all suggested methods but have still not got it right. Can close report with Esc if I do not press the magnifier. As soon as I press the magnifier, and press it again to reduce size to original, Esc does not work. But If I then click off the report (in the blue margin next to the report) Esc works.
 
I haven't got Access 2007+ on this machine to test it but what I think is happening there is that the button is retaining focus. I think you will find that not only the Zoom button acts this way.
 
I will continue to try and solve it, and will post if I find it. Thanks for the help.
 
If the button on the ribbon is keeping the focus then you have to create your own ribbon and in the CallBack function (or refactored function) send the focus back to your report.
 
Hi In 2003 this functionality worked fine, but not in 2007. Want to close a report by using Esc key. In 2007 can get it to partially work by making report modal. So I double click a form control and the report opens. Then press Esc and report closes. But if I use the magnifier to enlarge the report, then click the magnifier again to reduce the size, the Esc key does not fire. I first have to click somewhere outside the report then Esc works; only one extra click I know but I'd really like it to work like it used to in 2003. Then thought I'd do an On key Down event but get error 2585, "action cant be carried out while processing a form or report" Private Sub Report_KeyDown(KeyCode As Integer, Shift As Integer) 'trying to close the report with Esc If KeyCode = 27 Then DoCmd.Close acReport, "IndividualReportsNoParams" End If End Sub Any ideas how to get this functionality working Thank you

I think you had a good idea of how to do it. It happens to be the exact same way I tried to make the escape key work on the reports. Unfortunately the Access designers have some glitch where it throws the 2585 error. I fought this most of yesterday with no luck, but today I struck upon an idea that gave me success. It is not very elegant, but it does the job. What I had to do was set a timer on an open form and then have the form close the report. Right now I have the timer interval set to 5, so it happens pretty much instantly. In addition to setting the timer interval, I pass the name of the report to a variable on the form, so that the form knows what report to close. Luckily for me, I have one form that I always keep open and so I can use this form to close any report.

My code is as follows:
On the report:
Private Sub Report_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then Forms!frmSwt.RptEsc (Me.Name)
End Sub

On the form:
Dim Rpt As String 'dim this at the top of the forms module
Function RptEsc(TheRpt As String)
Rpt = TheRpt
Me.TimerInterval = 5
End Function

Private Sub Form_Timer()
If Me.TimerInterval = 5 Then
Me.TimerInterval = 60000
DoCmd.Close acReport, Rpt, acSaveNo
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom