Report preview does not contain current data

  • Thread starter Jennifer Crawford
  • Start date
J

Jennifer Crawford

I have an odd problem. I have a button on a form which
previews a report that is based on information from that
record. The problem is that if I make a change to the data
(when Me.Dirty = True) and then preview the report, that
change is not reflected in the report displayed. I can
only see the change if I move to another record, then move
back to the original record and preview the report again.

I realize that this is occurring because the record that
is displayed has not yet been updated to the table, which
is why when I move to another record (or a child record),
the report works (since that, by default, saves the
changed record). However, I need to be able to force that
save within VBA instead of requiring the user to manually
move from one record to the other.

I have tried setting the focus to a subform's field (since
I can manually go to a subform, click a field, and then
preview the report with the correct data), but this does
not seem to work when attempted in VBA, even though the
code to set the focus to the child field does not produce
any errors.

Any suggestions as to how to remedy this via VBA, so that
when the button is pressed, the report previewed contains
the most current data? DoCmd.Save only saves the form, not
the record, from what I can see (unless I'm missing
something).

Thanks,

Jennifer Crawford
 
F

Fredg

Jennifer,
You have the right idea.
You have to save the data before you can print it.

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName" etc.....
 
J

Jennifer Crawford

Oh, thank you!! That was it. I knew there had to be a way
to force the save - I just didn't know what it was.

Jennifer
 

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