473,770 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Report runs code when print previewing

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 is run again? This is causing
certain error problems.

1 Why does the code run for a print preview when the report already
exists?

2 What command do I use in code to find out if a report (or any other
object for that matter) is already open/loaded?

Thanks

Gord
Aug 2 '08 #1
11 7336
Gord,

What do you mean by "the report already exists?" If you can't see it in
print preview, it doesn't exist. If you have printed it before, it prints
and closes.

Bonnie
http://www.dataplus-svc.com

Gord wrote:
>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 is run again? This is causing
certain error problems.

1 Why does the code run for a print preview when the report already
exists?

2 What command do I use in code to find out if a report (or any other
object for that matter) is already open/loaded?

Thanks

Gord
--
Message posted via http://www.accessmonster.com

Aug 3 '08 #2
I 'open' the report from the navigation pane and see it in report view. The
records shown in the report are derived from the code I have written and are
displayed just fine. It is at this point I refer to the report as
'existing'. Once in report view, when I click print preview it would appear
my code is run again. (don't understand why?). When the code runs it
creates some errors because the report is already open (exists).

Thanks,

Gord
"bhicks11 via AccessMonster.c om" <u44327@uwewrot e in message
news:88179f7fcb bd9@uwe...
Gord,

What do you mean by "the report already exists?" If you can't see it in
print preview, it doesn't exist. If you have printed it before, it prints
and closes.

Bonnie
http://www.dataplus-svc.com

Gord wrote:
>>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 is run again? This is causing
certain error problems.

1 Why does the code run for a print preview when the report already
exists?

2 What command do I use in code to find out if a report (or any other
object for that matter) is already open/loaded?

Thanks

Gord

--
Message posted via http://www.accessmonster.com

Aug 3 '08 #3
Maybe I am missing something Gord (which is highly possible!). Are you
hitting print preview from File - Print Preview? When you open it the first
time you are in Preview mode. By the way, I am in Access 2003. Are you in
2007?

Bonnie
http://www.dataplus-svc.com

Gord wrote:
>I 'open' the report from the navigation pane and see it in report view. The
records shown in the report are derived from the code I have written and are
displayed just fine. It is at this point I refer to the report as
'existing'. Once in report view, when I click print preview it would appear
my code is run again. (don't understand why?). When the code runs it
creates some errors because the report is already open (exists).

Thanks,

Gord
>Gord,
[quoted text clipped - 20 lines]
>>>
Gord
--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200808/1

Aug 3 '08 #4
When you preview a report, the code is still alive. Access doesn't
prepare a static "copy" of the report which you can then just browse.
For example, whenever you move to a new page in preview, the Page
event always will fire, if you have one. So you shouldn't assume the
report is produced in a single pass, as in other languages, and base
your reporting strategies on that assumption. The user can page
forwards and backwards at will, and the code will continue to fire
multiple times on page breaks, control breaks etc. And be very
careful with referring to global variables in reports; if the user
starts the report and leaves it open in preview, or executing, then
goes off on some task, say data entry, that changes the global
variable, the report will be compromised. It will have picked up
different values of the same global variable, depending on the instant
that the reference was made.

Terry
Aug 3 '08 #5
I'm using 2007 and am self teaching. The next reply from TerryBell would
indicate that the code is run if you take too deep a breath. (I'm hitting
the print preview from the 'Home' tab and selecting 'Print Preview' from the
'Views' control.) If this is the way it has to work, then I can write
around the problem if I can determine if the report is already 'open' or
'loaded' (depending on the correct terminology). Do you know how to
determine if a report is already open?

Thanks,

Gord

"bhicks11 via AccessMonster.c om" <u44327@uwewrot e in message
news:881880facb 1c7@uwe...
Maybe I am missing something Gord (which is highly possible!). Are you
hitting print preview from File - Print Preview? When you open it the
first
time you are in Preview mode. By the way, I am in Access 2003. Are you
in
2007?

Bonnie
http://www.dataplus-svc.com

Gord wrote:
>>I 'open' the report from the navigation pane and see it in report view.
The
records shown in the report are derived from the code I have written and
are
displayed just fine. It is at this point I refer to the report as
'existing'. Once in report view, when I click print preview it would
appear
my code is run again. (don't understand why?). When the code runs it
creates some errors because the report is already open (exists).

Thanks,

Gord
>>Gord,
[quoted text clipped - 20 lines]
>>>>
Gord

--
Message posted via AccessMonster.c om
http://www.accessmonster.com/Uwe/For...ccess/200808/1

Aug 3 '08 #6
Terry,

Thanks for the info. How can I determine in code if a particular report (or
any object) is already open?

Thanks,

Gord
<te**********@g mail.comwrote in message
news:55******** *************** ***********@b30 g2000prf.google groups.com...
When you preview a report, the code is still alive. Access doesn't
prepare a static "copy" of the report which you can then just browse.
For example, whenever you move to a new page in preview, the Page
event always will fire, if you have one. So you shouldn't assume the
report is produced in a single pass, as in other languages, and base
your reporting strategies on that assumption. The user can page
forwards and backwards at will, and the code will continue to fire
multiple times on page breaks, control breaks etc. And be very
careful with referring to global variables in reports; if the user
starts the report and leaves it open in preview, or executing, then
goes off on some task, say data entry, that changes the global
variable, the report will be compromised. It will have picked up
different values of the same global variable, depending on the instant
that the reference was made.

Terry

Aug 3 '08 #7
Did you tell us where the code exists?
In a standard module?
In the report's module? (if so is it event code? what event?)
In a class module?

Did you tell us what the code is? Exactly what is it?

How about posting this code and any related code such a procedure
which is called from the code?

What are the "error problems"?

In fact, code is not run once if you take too deep a breath, let alone
twice. It may be run twice if you have placed it in an event that
occurs twice, or more.

CurrentProject. AllReports("Sup plier Phone Book").IsLoaded is true if
the "Supplier Phone Book" report is open, false if it is not, error
2467 if there is no report named "Supplier Phone Book", (Access
2007) .
On Aug 2, 10:52*pm, "Gord" <x1gor...@telus .netwrote:
I'm using 2007 and am self teaching. *The next reply from TerryBell would
indicate that the code is run if you take too deep a breath.
Aug 3 '08 #8
Gord, I've retracted my previous post, it was part right and part
wrong.
One thing is true, and that is when you preview a report, Access
prepares the first page, and doesn't necessarily prepare the next page
until you page down; so you shouldn't assume all the code is executed
when the user opens a report in preview mode. I think (not certain!)
the point at which code is executed is further complicated by the
existence or not of totals in control breaks and other report
properties.
You're best off not trying to predict this and design your report so
it doesn't have any dependencies on when the code is executed.

I'm curious as to why you need to determine whether or not the report
is open?

But if you must, here's a function that will tell you.

Function ReportOpen(Repo rtName) As Boolean
Dim rpt As Report
For Each rpt In Reports
If rpt.Name = ReportName Then
ReportOpen = True
Exit Function
End If

Next rpt
End Function

eg
ReportOpen("MyR eport1") will return true if the report is open, false
if it's not. Note, "Open" can be open in different states - normal,
print preview, design etc.

Aug 3 '08 #9
I'm using the report's 'On load' event which runs a small bit of code that
calls a procedure that does most of the work.

Private Sub Report_Load()

MyModule.MyProc edure

Me.RecordSource = "MyJustCreatedT able"

End Sub

As you see the record source for the report will be a table created by the
sub procedure. The way I want this to work and the way I have written the
sub, is to delete the table first (if it exists) and then create the table
and populate with records as determined by the rest of the code. The
portion of code in the sub that deletes the table is as follows:

Dim chkForExistTbl As TableDef
For Each chkForExistTbl In dBase.TableDefs
If chkForExistTbl. Name = "MyJustCreatedT able" Then _
dBase.TableDefs .Delete "MyJustCreatedT able"
Next

When I open the report from the navigation pane, the report opens just fine
with the just created table and records. Everything A O.K. While the
report is open in 'Report View' and I try to go to 'Print PreView' it would
seem my code runs again and generates the following error:

Run Time Error '3211'

The database engine could not lock table 'MyJustCreatedT able' because it
is already in use by another person or process.
When I click Debug, it is stalled on the line that is trying to delete the
table:

dBase.TableDefs .Delete "MyJustCreatedT able"

I assume this happens because the report itself is the process that is
'using' the table i.e. the table is it's recordsource.

In the above 'On load' event I added the following as the very first line of
code:

Me.RecordSource = ""

in the hopes that when my code runs while going into print preview, it
wouldn't see the table as being 'in use' and would allow my code to delete
the table. Again, this code works fine when opening the report from the
navigation pane. Everything A O.K. But now when I try to go into print
preview I get the following error:

Run time error '2191'

You can't set the Record Source property in print preview or after
printing has started.

So it would seen that print preview insists on the report as having it's
recordsource property set right at the get go.

My next thought was to make the first bit of code in the event check to see
if the report was loaded or not. (I had hoped (fingers crossed) that the
report wouldn't report itself as being loaded right at the beginning of the
event when opened from the navigation pane.) This is where I used a
modified version of your example (thank you) below as the first line of
code in the event:

If CurrentProject. AllReports("MyR eport").IsLoade d is true then exit sub

My thinking was that if the report was indicated as being loaded, then I
wouldn't bother running any of the code since this would be the event
triggered by going into print preview. Of course this doesn't work as the
report is indicated as being loaded before my code runs so I can't
distinguish from opening the report from the navigation pane or going into
print preview.

In either case of whether I have the report's recordsource set or not, after
I clear the error dialog with 'End' I go into print preview just fine. So I
could handle the problem with an error handler and suppress the error but I
am trying to be concise about this and not generate an error in the first
place.

I'm teaching myself Access from books/this newsgroup and I may be making an
incorrect assumption. As I understand, a report needs to have a
recordsource from an existing table (or query, which is itself based on
existing tables). This is why I create the table in the first place. I also
delete it and recreate it every time the report is run since the underlying
data (which is coming from a query) may have changed. Perhaps this an
incorrect assumption and I can create a temporary 'virtual' table within my
code to use as a recordsource for the report so I don't have to delete
anything?

Thanks,

Gord
"lyle fairfield" <ly************ @gmail.comwrote in message
news:9c******** *************** ***********@b1g 2000hsg.googleg roups.com...
Did you tell us where the code exists?
In a standard module?
In the report's module? (if so is it event code? what event?)
In a class module?

Did you tell us what the code is? Exactly what is it?

How about posting this code and any related code such a procedure
which is called from the code?

What are the "error problems"?

In fact, code is not run once if you take too deep a breath, let alone
twice. It may be run twice if you have placed it in an event that
occurs twice, or more.

CurrentProject. AllReports("Sup plier Phone Book").IsLoaded is true if
the "Supplier Phone Book" report is open, false if it is not, error
2467 if there is no report named "Supplier Phone Book", (Access
2007) .
On Aug 2, 10:52 pm, "Gord" <x1gor...@telus .netwrote:
I'm using 2007 and am self teaching. The next reply from TerryBell would
indicate that the code is run if you take too deep a breath.

Aug 3 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1775
by: scoimbra | last post by:
Hello there, I have a report in an access database that always prints to the MS Image Writer. I have to do this several times a day. Does any of you know how to implement a VB code to print this report to the MO Image Writer WITHOUT having to write the file name (and choose the directory) on the MOIW window everytime I choose to print this report?
0
1376
by: elgin | last post by:
I have a form which is formatted so as to print out for mailing. This form contains several option groups with checkboxes. These checkboxes have no data source; the state of the checkboxes are updated on the "on current" event that pulls the data from an underlying table. When I open the form, everything looks great, but when I do print preview (and/or print) the checkboxes in 3 of the option groups are all unchecked. When I cancel print...
1
2520
by: Scott | last post by:
Hello- I have a contol button on a form that I want to code to open a report (rptReviews), then display the print dialogue box so that users can select a printer. This report needs color, but most of my team has their default printer set to our departments monochrome printer. Thus i wanted to give them the option to run it to our color printer during the print process. Alternately, is there a way to code a button to drive a report to
5
3813
by: Stefan Bellon | last post by:
Hi all! I am embedding Python into a GUI application in a way that the GUI is scriptable using Python. Now I have come to a problem that when the user puts a "sys.exit(0)" into his script to end the script, not only the script is terminated, but also the GUI application itself. This is not the intended behaviour. As in Python itself you can catch SystemExit, I think this should be
1
3276
by: G Gerard | last post by:
Hello When I want to print a report using code I normally use the following code DoCmd.OpenReport "RptName", acViewNormal This works OK when I'm only printing one copy of the report. What I'm trying to do now is open the CommonDialog using .ShowPrinter and set the number of copies to print from the CommonDialog
29
2969
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any bug , i am still c++ beginner
8
1757
by: dponce | last post by:
What's up forum, Is this possible? Is there a way to have access ask the end user which report you want to print? If so, how.
2
2166
by: PW | last post by:
Hi, It's an Access 2003 report. The underlying query runs fast on my PC but I have to hit Ctrl-Break to stop the report as it is stuck on "formatting page". The report runs fast on my wife's PC but not mine. I have tried relinking the tables and compacting and repairing the database on my PC but no luck. We are both using WinXPSP3.
1
10914
by: maximus tee | last post by:
hi, i'm using Python 2.5 and Windows XP. i'm wondering whether is a way to enlarge the font size when print out to CMD window. For eg: print "Hello World". It will print out with standard size in the CMD window. Is there a way in python to enlarge the font size? thanks maximus
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.