refresh Query & form before Export

Dear Experts

I'm building a simple tool to add a cover sheet to an existing PDF. The cover sheet is created by the user entering details in 3 fields in a form ([CandidateName], [Client], [Role]). This form shares the same underlying query "Ready4Report" as the Report "CoverSheet".  The cover sheet is then exported to PDF and the merge then happens.

This works all fine but the underlying query & the report doesn't update itself prior to export.  The code I'm using is below, can anyone help?

DoCmd.Save


'create CoverPage
DoCmd.OutputTo acOutputReport, "CoverSheet", "PDFFormat(*.pdf)", "C:\Users\Digby Edwards\Desktop\CV Cruncher\System Files\CoverPage.pdf", False, "", , acExportQualityPrint


'Start of merge process
Dim FormattedCV As String
FormattedCV = "C:\Users\Digby Edwards\Desktop\CV Cruncher\CSCR " & Me.CandidateName & ".pdf"
Dim CommandLine As String
Dim CoverPage As String
Dim CandidateCV As String
Dim OutputDoc As String
Dim OutputDoc4Move As String


'Collates Docs for CommandLine
CoverPage = """C:\Users\Digby Edwards\Desktop\CV Cruncher\System Files\CoverPage.pdf"""
CandidateCV = """C:\Users\Digby Edwards\Desktop\CV Cruncher\System Files\OwnCV.pdf"""
OutputDoc = """C:\Users\Digby Edwards\Desktop\CV Cruncher\System Files\OutputCV.pdf"""

'Does the joiney bit
CommandLine = """C:\Program Files\PDFtk Server\bin\pdftk.exe"" " & CoverPage & " " & CandidateCV & " cat output " & OutputDoc

'MsgBox CommandLine
Call Shell(CommandLine, vbNormalFocus)

'Moves end Result to desired Folder
OutputDoc4Move = "C:\Users\Digby Edwards\Desktop\CV Cruncher\System Files\OutputCV.pdf"
FileCopy OutputDoc4Move, FormattedCV

Open in new window

correlateAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
A query is executed only when called, so there's no way to "refresh" that query - you just run it, and you'll get the most recent results.

If the query refers to other objects (like a Form), then it would use whatever values are on the form at the time, so there's no need to refresh the Form either.

You may need to change the point at which you open the report, of course - but you haven't shown us that. Remember too that you should open the report using acViewPreview - don't use acViewReport.
0
Dale FyeCommented:
If the query refers to a record in a table, and the fields on the form are bound to that table, then you need to make sure that the value of those controls is written to the table before you run your query.

I use:

Me.Dirty = False

as the first statement in my button click events to ensure that the the record has been saved.
0
PatHartmanCommented:
Since Me.Dirty = False is a trick used to skirt a very rare issue with the normal save method, I suggest adding a comment that this will save the record.  I also prefer to test if a record is dirty before saving it.

If Me.Dirty = True Then
    DoCmd.RunCommand acCmdSaveRecord
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
correlateAuthor Commented:
thanks for your help on this - the me.dirty trick works a treat
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.