refresh Query & form before Export

correlate
correlate used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
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.
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010
Commented:
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.
Distinguished Expert 2017
Commented:
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

Author

Commented:
thanks for your help on this - the me.dirty trick works a treat

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial