Preview Report

G

Guest

I have the following code in a command button on my form. It's shows a
preview of a report that is created from my current record on my form. If I
open my form and then change some data in a record and then click to preview
the report it doesn't show the change I made. But if I close the report
preview and go back to the form and then click on preview report again the
change is there. Why won't it show the change the first time I click to
preview?

Dim stDocName As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMennuVer70
stDocName = "CorrectiveAction"
DoCmd.OpenReport stDocName, acPreview, "qryCAFilter"
 
J

Joshua A. Booker

SS,

Add this before you preview the report:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Access doesn't save the record until you move to another record or close or
something so you have to force the save first.


HTH,
Josh
 
G

Guest

Hello again Joshua,

Nope, that didn't work. It's still doing the same thing. Is there a way to
maybe refresh the data before previewing it?
 
T

Tom Ellison

Dear Secret:

I recommend that after you change the data on your form, open the table and
look. Have the changes been recorded?

Changes are not recorded every time you type one letter on the keyboard. It
could be done this way, but the computer would be incredibly slow to do such
massive changing. So, the recording of changes is deferred.

It may be useful to force saving changes when the form on which you make
changes "deactivates" meaning the focus moves to another form, or to your
report's preview.

Solving your problem is completely different if the changes have not yet
been saved from the solution if they have. Let's find the source of the
problem before doing work to solve it.

Tom Ellison
 
J

Joshua A. Booker

SS,

What does the following line do? Try removing it.

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMennuVer70

You could try me.requery, but it shouldn't be necessary. And you will lose
your current record.

Josh
 
G

Guest

Tom,
I just verified that the changes are being made in the table. What I did was
change some data in a control and then click the preview report button. The
data was not updated on the report but I left that preview opened and then
opened the table and the data was changed there so it is updating the record
right away.
 
T

Tom Ellison

Dear Secret:

With the problem on the report side, it is essential to close the report
including preview and re-open them to see the changes. Once the query's
dataset has been placed in memory, it ignores any changes to the underlying
data.

Tom Ellison
 
G

Guest

So what you're saying is that if I make any changes to the record I need to
open and close the report and then re-open it to see the changes?
 
T

Tom Ellison

Dear Secret:

Absolutely!

Tom Ellison


Secret Squirrel said:
So what you're saying is that if I make any changes to the record I need
to
open and close the report and then re-open it to see the changes?
 
G

Guest

Ok then! There's no way to "refresh" the data in the code that opens the
preview report?
 
T

Tom Ellison

Dear Secret:

There's no need to refresh the data when opening the report, preview or not.
The point is to open it. It refreshes every time you open it.

That's the point. Close it and open it.

I'm sure I'm missing your point here, somehow. What is it?

Tom Ellison
 
G

Guest

I think we're on the same page here. I'll give you a better explanation of
the problem at hand. I have two command buttons on my form. One is for
previewing a report and the other is for creating a snapshot format file of
the report (for emailing purposes). If a record is created and then you click
on the "snapshot file" button it creates the file and everything is fine.
From that point if you also just want to click preview report and print the
report, that works fine too. But after you click on the "snapshot file"
button and then go back to change data in a control and then try to create a
new file it doesn't show the changes that were just made. If I was to then go
and try to preview the report from the "preview" button it also doesn't show
the changes. But if I was to click on the button and open the preview and
then close it and open it again everything looks fine. So basically neither
command button that I have will update any changes. Does this make sense?
 
T

Tom Ellison

Dear Secret:

Once you have opened a preview of the report, you can move from that preview
to printing the report or creating the snapshot. The report will not change
for any changes to the data unless you close the preview and reopen the
report.

To make what you describe work as you want, you should have two copies of
the report. Run one for the preview and a different one for the snapshot.
That way, it won't use the already opened preview of the report to produce
the snapshot.

Alternatively, you could have the snapshot button close the preview first.

Cl;icking the preview button when a preview is already open just displays
that preview. Here, the alternative of closing the preview and rebuilding
it is the only alternative I can offer.

But, as long as the report is "open" it won't change due to changes in data.
The entity that is "the report" is a singular entity. If it is open, then
the currently open copy of the report is the report for all purposes.

I can understand that this is mysterious to some extent, but it is reality.
I can think of only the two alternatives above to solve your problem.

Finally, I'll offer you an analogy. If you print a report and then change
the data, will the printed pages change? I'm not just being facetious.
This is really a version of the same thing.

Tom Ellison
 
G

Guest

Tom,
The reason for the two different command buttons is so that when the
snapshot file is fired it will not open the preview. I have code in there
that says;

Reports("rptCorrectiveActionReport").Visible = False

That will just make it flash quickly and then create the file. Then the code
automatically sends an email out with that file as the attachment. All I want
my users to be able to do it click a button and have it create the file and
email it. The other button is for users who just want to print the form and
not email it. That's why I have two command buttons. Both commands are not
run at the same time. The users have a choice to either email it or print it.
So they will never be opened at the same time. Do you still think I need to
have two different reports?

So what happens is if someone sends the snapshot file and then goes back and
changes data and then sends the file again it doesn't carry the changes over
to the report. If they were to send it and then send it again then it would
have the changes. Does that make sense?
 
T

Tom Ellison

Dear Secret:

I'm confused. Does it happen that someone does this:

1. Open the preview

2. Change the data

3. Create the snapshot

The preview from step 1 is still open. The snapshot does not reflect the
changed data.

Is that the case where there's a problem? Then, yes, keep 2 copies of the
report so the already opened preview does not "bleed" into the snapshot.

If there's some other case, please explain in a chronology so I can see it.

Tom Ellison
 
G

Guest

Here's the order of how it goes:

1. Open Form
2. Add new Record (enter all data needed)
3. Create the snapshot file

No preview of the report is opened in the above process except for when the
snapshot file is created. It's opened for a second and then closed once the
file is created. I showed you the code that does this in my last post.

Now while I'm still in the form I decide to make a change to some data

4. Make change to data
5. Create the snapshot file after data has been changed on the form(at this
point the snapshot still shows the original data before it was just changed
in step 4)
 
T

Tom Ellison

Dear Secret:

Just two things to check.

Are the changes recorded in the table before you run the snapshot?

When DOES the change show up in the snapshot? Do you have to close the
application and reopen it first? Or what?

Tom Ellison
 
G

Guest

I did verify that the changes are being made in the table before I run the
snapshot. The changes will show up in the snapshot after I close it and
re-open the snapshot.
 
T

Tom Ellison

Dear Secret:

Too bad about all the confusion.

Once you are viewing a snapshot, it won't change. Probably your computer is
low on query fluid.

The snapshot is not at all flexible in this way. Nor is a preview. Like a
printed page, they don't update. It has to go back and be recreated to see
the new data.

Tom Ellison
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top