I have a report that I want to delete once print preview is closed by the user. I tried this: -
If stDocRemote = "1" Then 'delete external reports
-
Do While CurrentProject.AllReports(stDocName).IsLoaded
-
Loop
-
-
DoCmd.DeleteObject acReport, stDocName
-
-
End If
-
And this puts me in an endless loop that I must break out of. How can I code this?
Thanks,
Tux
9 8737
Hello, Tux.
I recommend you another approach. -
-
'declare object variable to handle report events in the form module
-
Dim WithEvents rpt As Access.Report
-
-
Private Sub Command0_Click()
-
-
'make copy of report and open it (illustration purpose only)
-
With DoCmd
-
.CopyObject NewName:="rptNew", SourceObjectType:=acReport, _
-
SourceObjectName:="rpt"
-
.OpenReport "rptNew", acViewPreview
-
End With
-
-
'set object variable to the opened report
-
Set rpt = Reports("rptNew")
-
'tune its OnClose property
-
rpt.OnClose = "[Event Procedure]"
-
-
End Sub
-
-
'now report is closed and could be deleted
-
Private Sub Form_Timer()
-
Me.TimerInterval = 0
-
DoCmd.DeleteObject acReport, "rptNew"
-
End Sub
-
-
'report close event
-
'since report is still open it couldn't be deleted
-
'event handler sets form timer and yields execution to Access
-
Private Sub rpt_Close()
-
Me.TimerInterval = 1
-
End Sub
-
@FishVal - First, 2 Assumptions:
- The Name of the Form that Opens your Report is Form2.
- The Report Name is rptEmployees.
- Place the following code in the Timer() Event of Form2, and set the Timer Interval = 0.
-
Private Sub Form_Timer()
-
On Error Resume Next
-
DoCmd.DeleteObject acReport, "rptEmployees"
-
Me.TimerInterval = 0 'Disable
-
End Sub
-
- 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'.
- DoCmd.OpenReport "rptEmployees", acViewPreview, , , acWindowNormal, "Preview"
- Place the following code in the Close() Event of the Report:
- Private Sub Report_Close()
-
If Me.OpenArgs = "Preview" Then
-
'Wait 2 seconds after closing
-
Forms!Form2.TimerInterval = 2000
-
End If
-
End Sub
- Code has been tested and is fully operational.
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
@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".
Thanks for the explanation FishVal. I'll give your code a go and see what happens.
Tux
@tuxalot
Why not simply Open the Report in the External Database from the Current Database? Wouldn't that solve all your problems?
Yes! However the queries for the reports reside in my FE db. The StateReports db only houses the reports themselves.
@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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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",...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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...
| |