473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

delete report after print preview is closed

tuxalot
200 100+
I have a report that I want to delete once print preview is closed by the user. I tried this:

Expand|Select|Wrap|Line Numbers
  1. If stDocRemote = "1" Then        'delete external reports
  2.         Do While CurrentProject.AllReports(stDocName).IsLoaded
  3.         Loop
  4.  
  5.         DoCmd.DeleteObject acReport, stDocName
  6.  
  7. End If
  8.  
And this puts me in an endless loop that I must break out of. How can I code this?

Thanks,

Tux
Mar 30 '09 #1
9 8737
FishVal
2,653 Expert 2GB
Hello, Tux.

I recommend you another approach.

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'declare object variable to handle report events in the form module
  3. Dim WithEvents rpt As Access.Report
  4.  
  5. Private Sub Command0_Click()
  6.  
  7.     'make copy of report and open it (illustration purpose only)
  8.     With DoCmd
  9.         .CopyObject NewName:="rptNew", SourceObjectType:=acReport, _
  10.             SourceObjectName:="rpt"
  11.         .OpenReport "rptNew", acViewPreview
  12.     End With
  13.  
  14.     'set object variable to the opened report
  15.     Set rpt = Reports("rptNew")
  16.     'tune its OnClose property
  17.     rpt.OnClose = "[Event Procedure]"
  18.  
  19. End Sub
  20.  
  21. 'now report is closed and could be deleted
  22. Private Sub Form_Timer()
  23.     Me.TimerInterval = 0
  24.     DoCmd.DeleteObject acReport, "rptNew"
  25. End Sub
  26.  
  27. 'report close event
  28. 'since report is still open it couldn't be deleted
  29. 'event handler sets form timer and yields execution to Access
  30. Private Sub rpt_Close()
  31.     Me.TimerInterval = 1
  32. End Sub
  33.  
Mar 30 '09 #2
ADezii
8,834 Expert 8TB
@FishVal
  1. First, 2 Assumptions:
    1. The Name of the Form that Opens your Report is Form2.
    2. The Report Name is rptEmployees.
  2. Place the following code in the Timer() Event of Form2, and set the Timer Interval = 0.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Timer()
    2. On Error Resume Next
    3.   DoCmd.DeleteObject acReport, "rptEmployees"
    4.   Me.TimerInterval = 0            'Disable
    5. End Sub
    6.  
  3. Assuming you only want to Delete the Report after it is Open in 'Preview' Mode, open the Report from your Form and pass to it an OpenArgs = 'Preview'.
    Expand|Select|Wrap|Line Numbers
    1. DoCmd.OpenReport "rptEmployees", acViewPreview, , , acWindowNormal, "Preview"
  4. Place the following code in the Close() Event of the Report:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Report_Close()
    2. If Me.OpenArgs = "Preview" Then
    3.   'Wait 2 seconds after closing
    4.   Forms!Form2.TimerInterval = 2000
    5. End If
    6. End Sub
  5. Code has been tested and is fully operational.
Mar 30 '09 #3
tuxalot
200 100+
Thanks for the replies.

ADezii - if possible I would prefer not to put code in the reports themselves, and was looking for a solution that could be coded from my main form.

FishVal - let me see if I understand. The code you provided makes a copy of the report, after which time it deletes the copy? I'm not sure this will give me what I need so allow me to explain. The reports that I wish to delete are those that are transferred from a linked db via DoCmd.TransferDatabase. Please help me to understand your code and if it would apply in my situation.

Thanks again,

Tux
Mar 30 '09 #4
FishVal
2,653 Expert 2GB
@tuxalot
Report copying in the example I've posted is for illustration purposes only.
The only reason for it was to have a renewable copy of a report to delete while testing the code.
You definitely don't need this part. The rest will work for you, just replace "rptNew" report name with whatever you need.

The logic of the code is as follows:
  • Open report.
  • Set a form module global object variable declared with events to opened report object.
  • Thus the report events could be handled in the form module.
  • Once the report object has triggered Close event, event handling code in the form module (sub rpt_Close) is being called. At this point the report could not be deleted because the report is not yet closed. Therefore, instead of delete the report, code sets form timer and returns execution flow back to Access which closes the report and then triggers Form_Timer event sub where the report is actually deleted.
  • Timer interval value is not important because VBA execution is not asynchronous. That means no event will be triggered until Access perform all actions necessary for report closing. So, in the example timer interval is set to a least possible value - 1 ms. Like saying "one moment", though, actually, it may take thousand "moments".
Mar 30 '09 #5
tuxalot
200 100+
Thanks for the explanation FishVal. I'll give your code a go and see what happens.

Tux
Mar 30 '09 #6
ADezii
8,834 Expert 8TB
@tuxalot
Why not simply Open the Report in the External Database from the Current Database? Wouldn't that solve all your problems?
Mar 30 '09 #7
tuxalot
200 100+
Yes! However the queries for the reports reside in my FE db. The StateReports db only houses the reports themselves.
Mar 30 '09 #8
ADezii
8,834 Expert 8TB
@tuxalot
Hello tuxalot, IMHO I do not think that the current logic is sound in that:
You are Importing Reports from an External Database whose Record Sources reside locally. After Previewing these Reports, you are then Deleting them.
Mar 30 '09 #9
tuxalot
200 100+
I know it sounds strange but...
The reports reside externally because the main db may roll out before the state reports db. The state reports db may update several times each year, so I need an easy way to update the state reports without affecting the FE or BE. The queries for the State Reports reside locally because some local reports use the same queries.

At max, if all external reports were transferred and the main db saved, the added bloat may approach 15mb (each report uses a pdf as it's background and they average 3mb each report). So we're not talking about a significant amount I just figured if I could tidy things up it would be better.

I suppose another solution may be to perform the deletion on db shut-down, or every 24 hours if the user keeps their pc running.
Mar 31 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: hawk | last post by:
I am creating a series of custom reports, whose parameters are specified through combo boxes in a form, which then generates a custom report based on a series of calculation queries. My problem is...
1
by: sea | last post by:
I have Access 2002 and I am writing this application with a custom menu bar that has a print preview button -- the start up options hide the design window. The problem is that when an open form is...
0
by: cabrenner | last post by:
First of all, I have been using the newsgroup to find answers to my development questions for several months, and it has been extremely helpful. I have an access app which closes all toolbars...
5
by: nick_faye | last post by:
Hi, I am still a newbie to VB and using MS Access 2000. I am currently trying to provide a preview of reports before printing them. My program is simple: AC.DoCmd.OpenReport "MyReport",...
0
by: John Smith | last post by:
Hello, I am developing a VB.NET 2003 application that will use lots of Crystal Reports. Sometimes the users will preview a report in a Crystal report viewer, and sometimes they will send the...
8
by: paii, Ron | last post by:
I have a report that is opened in preview mode, the users can view it then send it to a printer. I want to; in the same command display a dialog box with "Yes/No" to confirm the next step. How do I...
1
by: mailjaneen | last post by:
Hello, can someone help me. I want to display some fields on a report in print preview (i.e. instructions), that I don't want to print to the printer or export to file. I can't seem to find any...
11
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code...
4
by: scubasteve | last post by:
I've developed a product pricing application for a client in AC2007. They enter all the data on the one main form, then click a button to open a printable report in Print Preview. My problem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.