Solved

Report Closing

Posted on 1998-06-22
14
242 Views
Last Modified: 2012-08-14
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
Comment
Question by:bav061998
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 1

Expert Comment

by:Anita030598
ID: 1975643
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
 
LVL 1

Expert Comment

by:Anita030598
ID: 1975644
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
 

Author Comment

by:bav061998
ID: 1975645
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
 
LVL 12

Expert Comment

by:Trygve
ID: 1975646
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
 

Author Comment

by:bav061998
ID: 1975647
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
 

Author Comment

by:bav061998
ID: 1975648
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
 
LVL 12

Expert Comment

by:Trygve
ID: 1975649
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:bav061998
ID: 1975650
Anybody else?
0
 
LVL 3

Expert Comment

by:chapie
ID: 1975651
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
 
LVL 1

Expert Comment

by:CEBAKA
ID: 1975652
You should do this on the unload event of the report
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1975653
The UnLoad event does not exist for reports, just for forms.
0
 

Author Comment

by:bav061998
ID: 1975654
Trygve is right.
0
 

Author Comment

by:bav061998
ID: 1975655
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
 
LVL 1

Accepted Solution

by:
Anita030598 earned 60 total points
ID: 1975656
Sure.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now