Link to home
Start Free TrialLog in
Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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.
SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Crowfoot

ASKER

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