Printing a report to a PDF file via a button on a 'search' form.

popguru

New member
Local time
Today, 20:49
Joined
Dec 11, 2013
Messages
7
Good afternoon everybody.

I'm building an application to record engineer input in Events (jobs) for an engineering company.

My main tables are Products, Builds and Events, together with fifty or so reference and ancillary tables which aren't really relevant to this particular head-scratcher.

A Build is derived from a Product and an Event is applied to a Build. An Event includes a sale, a service, a warranty repair and so on. Over time, multiple Events will be logged against a Build.

I have a searchable Events form (Search_Events), containing a subform (Search_Events_sub) whose contents dynamically change to reflect data entered in a variety of unbound fields in the main Events search form. Needless to say, the glue that holds things together is the Event_ID field.

On my Search_Events form, I'd like to place two buttons (Rpt_Event_client and Rpt_Event_internal) which will allow the user to print either a client or an internal copy of the event in question. The reason I want to use separate buttons rather than one button for both copies is that it's quite likely that different engineers will work on different parts of an Event's build, test and sign off process, and will want to print off and annotate the internal report, whereas only the final report will be sent to the client. Also, there will be some slight differences between the visible fields on each report (time and materials logged etc).

So far, I've managed to get the Rpt_Event_internal button to open the relevant Event report in preview mode, using the following on the button's 'on click' event:

DoCmd.OpenReport "Rpt_Event_internal", acViewPreview, "", "[Event_ID]=[Forms]![Search_Events]![Sub].[Form]![s_Event_ID]", acWindowNormal, ""

(In the subform, Event_ID is referenced as s_Event_ID because I'm using an nZ function in most of the search fields so that the results filter dynamically)

So far, so good: this works fine. However, from a usability perspective, and based on the fact that this will be the most-used feature, I'd really like to be able to have the button do the following:

- print the relevant report, based on Event_ID as above to a PDF file

- synthesise the filename of the report along the lines of "Event_" & [Event_ID] & "_Client_Copy_" & [Date()] & ".pdf"

- and to then have the standard 'save as' Windows location browser/file explorer dialogue box appear so the user can choose where to save the file. I don't want the filepath to be hardwired, rather I need the users to be able to decide where to save the file.

In my head, I was hoping this would be relatively straightforward but, as ever, I'm really struggling. Despite using Access for several years now, I just don't seem able to really absorb or understand VBA syntax. Thankfully, it's not my fulltime job. I'm using Access 2013.

Could anybody help, please (ideally with some explanatory notes in the vain hope that I might be able to understand).

Thanks very much in advance,

Martin
 
Last edited:
To be honest popguru I've seen your thread a few times but skipped it because it was just too lengthy and not to the point. I'm sure others have reacted the same that's why you've not had a reply yet.

I've extracted the main points from your post:
...I'd really like to be able to have the button do the following:

- print the relevant report, based on Event_ID as above to a PDF file

- synthesise the filename of the report along the lines of "Event_" & [Event_ID] & "_Client_Copy_" & [Date()] & ".pdf"

- and to then have the standard 'save as' Windows location browser/file explorer dialogue box appear so the user can choose where to save the file.
You mentioned it should be easy and unfortunately it isn't. Your problem needs to be solved in three parts:

1. Saving the Access 2003 report as a PDF:
http://www.lebans.com/reporttopdf.htm

2. Filtering the report when outputting to PDF:
http://www.access-programmers.co.uk/forums/showthread.php?t=206372&highlight=outputto
... post #10 explains how to filter so ignore the loop and the OutputTo parts of the code.

3. The file save as dialog - as for this one you should be able to research ways to do this. It's possible there's code in leban's link above that already does this so have a look.
 
vbaInet.

He is using 2013 so he can use the built in PDF output. It's true that in 2003 you had to use Lebans solution.

'Use Built in PDF with Access 2007 or higher
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFolderPath & "\" & strFileName & ".pdf", True
 
vbaInet.

He is using 2013 so he can use the built in PDF output. It's true that in 2003 you had to use Lebans solution.

'Use Built in PDF with Access 2007 or higher
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFolderPath & "\" & strFileName & ".pdf", True
The post was too long I read that as 2003. Good spot ions.
 

Users who are viewing this thread

Back
Top Bottom