• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Report Closing

I am calling my report from a VB application. Where I refer to MS Access and load the report directly maximized. When user closes the report by either selecting File->Close or x mark of the Report Window or x mark of the Access Window, I want to ask the user whether he really wnats to close the report. If he says No, I want the report to not closed. How can I do this? Also if he says Yes, I want the whole Access to be closed, not just the report.
0
bav061998
Asked:
bav061998
  • 6
  • 3
  • 3
  • +2
1 Solution
 
Anita030598Commented:
For File->Close you can write your own function to do all you want. However, for the other two options, as per my knowledge, you will not be be able to stop closing the report.

To close the Access itself, in Report_Close() event procedure you can add the code,

Application.Quit

For File->Close, I will provide you the function and details within few minutes.

0
 
Anita030598Commented:
Write a function as below in a module.

Public Sub CloseReport()
    Dim nResponse As Integer
   
    nResponse = MsgBox("Do you want to close the report?", vbYesNo + vbQuestion, "<Title>")
    If nResponse = vbYes Then
        'Close the Access
        Application.Quit
    End If
   
End Sub

Go to Customize... (Right Click on the tool bar).
Select Close Button on the tool bar, right click and get the properties.
Set the On Action property to the new procedure CloseReport.

This will take care of asking the question to the user when he selects File->Close or he clicks on the Close button on the tool bar.

When user clicks on 'x' what you get is only Report_Close Event. But in that event, you will not be able to stop closing the report. So, asking the question to the user in that event will not really help.
0
 
bav061998Author Commented:
Anita, thank you for your reply. For now, I will re-open for others to answer. If I don't get any better answer from others, I will give you the points.

-bav
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
TrygveCommented:
Sorry ! The Close event can not be cancelled. There are two possible solutions to your request.

1) Adjust Anitas code. You will have to have some "dummy" form that you open in the Close event for the report if the user answers No to the question if he/she wants to clode the report. You should include a field on this dummy form to hold the name of the report and another field to hold the filter used. Then in the OnClose event for the report. Open the dummy form, set the report name field to me.name and the filter field to me.filter. The dummy form should have a timer function. Set the timer intervall to 3000 (3 seconds), Insert an OnTimer event that do the following;
docmd.openreport, me![Report Name field], acViewPreview , , me![Filter field]
me!TimerIntervall = 0 ' Resets the timer.
docmd.close

This may sound like a troublesome way to go, but the dummy form can be used for all your reports.

2) Redesign your application so that it is not possible to close your reports without using a button the you control the code for. This way you close the report and you can have it "your way". This involves some coding and I not 100% sure that you will get it bulletproof, but it could be worth looking into.

I would recommend approach number 1.
If you need more details, please let me know.

Trygve
0
 
bav061998Author Commented:
trygve, thanks for replying. I have tried your first suggestion. But it's not that satisfactory, it has problems.

Problems in the code in your answer,

1. It's not me!TimerIntervall, it is Me.TimerInterval.

2. docmd.close will close the report but not the form.

Anyway, that's not a big deal. I could figure out what to do.
But the major problem is report gets closed and re-opened. User can clearly see the report going away and coming back. It's not acceptable! I want the opened report to remain as it is.

I did not clearly understand your 2nd suggestion, can you please explain a little more about it. Thanks.

-bav
0
 
bav061998Author Commented:
Also one more problem with the above solution is, when user closes the Access Application window itself (using x), it does not work. Just gives the message and whatever user selects, it just goes away, doesn't even re-open.
0
 
TrygveCommented:
I tried some tricks involving turning of the screen update, but I could not get it work 100% without showing that the report reopens. I think perhaps your user has to see this.

Change the docmd.close line to DoCmd.Close acForm,me.FormName,acSaveNo  and it should close the form instead of the report.

On closing Access altogether, I don't know how we should prevent this.

If you want you may reject my answer and let other Experts have a go.
0
 
bav061998Author Commented:
Anybody else?
0
 
chapieCommented:
unless there is an API method for removing the X in the corner of the Access Application, you cannot cancel the close event when this is clicked
0
 
CEBAKACommented:
You should do this on the unload event of the report
0
 
TrygveCommented:
The UnLoad event does not exist for reports, just for forms.
0
 
bav061998Author Commented:
Trygve is right.
0
 
bav061998Author Commented:
Anita, can you please post your answer and lock it again? I did not get anything more than what you said. And currently I have implemted the FileClose using your method. And left other things as it is. So, I guess you deserve the point.Thanks to all.

-bav
0
 
Anita030598Commented:
Sure.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 6
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now