Solved

Report Closing

Posted on 1998-06-22
14
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

695 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