473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Save report to PDF with automatic file naming?

I currently have a form that opens a query that retrives information for one record. I have a report based on that query. I would like to be able to save that report as a PDF with a filename that includeds three labels from that information. (i.e. [LabID] [SampleID][DateSampled].pdf)

Is this possible?

Thanks
Jan 15 '14 #1
7 4448
NeoPa
32,556 Expert Mod 16PB
Not sure how a filename can include three labels but you should be able to specify the filename in the command that you call to print the report to PDF.

What's your actual question? You include no example code or anything indicating what stage you're at. It's hard to know what exactly you want help with.
Jan 15 '14 #2
GKJR
108 64KB
Are you trying to do this with VBA or some other Access routine? I can think of a way to create the name of the file with VBA. From there it shouldn't be too difficult to send it to a PDF. I think there is a macro procedure you could create and then have Access translate it to VBA. I've thought about implementing something to this effect in one of my projects, but I never actually committed to it.

Note that when you assign a value to strFileName, you can replace "CurrentProject.Path" with any directory you want. Using this property will put the new file into the same folder your database is in.

Expand|Select|Wrap|Line Numbers
  1. Dim db as Database
  2.     Set db = CurrentDb
  3. Dim rstQuery = Recordset
  4.     Set rstQuery = db.OpenRecordset("Name of Your Query in Quotes", dbOpenDynaset) 
  5.     'This query needs to contain the fields LabID, SampleID, and DateSampled
  6. Dim strFileName As String
  7.  
  8. With rstQuery
  9.     strFileName = CurrentProject.Path & _
  10.         "\Lab ID - " & !LabID & _ 
  11.         "\Sample ID - " & !SampleID & _ 
  12.         "\Date Sampled - " & !DateSampled & ".pdf"
  13. End With
  14.  
  15. 'You could alternately use the following to shorten the name of the file, but it may be hard for a user to understand:
  16. 'With rstQuery
  17. '    strFileName = CurrentProject.Path & "\" & !LabID & "\" & !SampleID & "\" & !DateSampled & ".pdf"
  18. 'End With
  19.  
I hope that this helps you. I'm not an expert but I think this may put you on the right track with creating the name of the file. Maybe someone else can respond that knows the process for sending it to a PDF and specifying the name of the file as "strFileName".
Jan 16 '14 #3
Neo, I dont currently have a command to call it to PDF. Currently is just opens a report "Prox Report". When I do a print and select the PDF printer, the default name is "Prox Report". I am wondering if I define the file name by the current record using the "LabID SampleID Date Sampled". So the filename would look like "87306 Auto Sample 1.2.2014" or similar without having to type it in each time a do a report. If not I can rename it each time I print but would rather avoid possible errors by having it use the information from the DB.

Does this help. I can post the code for the query if that would help also.

GKJR,
I appreciate your work there, but I cant seem to get it to work, where would I place that code? It seems to error on the
Expand|Select|Wrap|Line Numbers
  1. Dim rstQuery = Recordset
It says that it expects end of statement at the =?

Thanks again
Jan 28 '14 #4
Heres what the query looks like.

Expand|Select|Wrap|Line Numbers
  1. SELECT Data.[Lab ID], Data.[ADL Pan Weight], Data.[ADL Pan  Sample Wt], Data.[ADL Pan  Dry Sample Wt], Data.[Residual Moisture], Data.[Ash Dry], Data.[Volatile Dry], Data.[Sulfur As Determined], Data.[BTU As Determined], ([ADL Pan  Sample Wt]-[ADL Pan  Dry Sample Wt])/([ADL Pan  Sample Wt]-[ADL Pan Weight])*100 AS ADL, (1-[ADL]/100)*[Residual Moisture]+[ADL] AS Moisture, (1-[Moisture]/100)*[Ash Dry] AS [Ash AR], (1-[Moisture]/100)*[Volatile Dry] AS [Volatile AR], [BTU As Determined]/(1-[Residual Moisture]/100) AS [BTU Dry], (1-[Moisture]/100)*[BTU Dry] AS [BTU AR], [BTU Dry]/(1-[Ash Dry]/100) AS [MAF BTU], 100-([Ash Dry]+[Volatile Dry]) AS [Fixed Carbon Dry], 100-([Moisture]+[Ash AR]+[Volatile AR]) AS [Fixed Carbon AR], Data.Customer, Data.[Sample Identification], Data.[Date Sampled], Data.[Date Received], Data.Description, Data.[Sample Wt], [Sulfur As Determined]/(1-([Residual Moisture]/100)) AS [Sulfur Dry], [Sulfur Dry]*(1-([Moisture]/100)) AS [Sulfur As Received], Customers.CompanyName, Customers.BillingAddress, Customers.City, Customers.State, Customers.PostalCode, Customers.Department
  2. FROM Customers INNER JOIN Data ON Customers.CustomerID = Data.Customer
  3. WHERE (((Data.[Lab ID])=[Lab ID#]));
  4.  
Jan 28 '14 #5
GKJR
108 64KB
Sorry about that. I didn't test that code I just wrote it into the reply. It should say
Expand|Select|Wrap|Line Numbers
  1. Dim rstQuery As Recordset
Jan 28 '14 #6
GKJR
108 64KB
My original thought was that you could create a button on your form and write some code in the "On Click" event that would open the report with the appropriate filter criteria and then print it to a pdf file with the file name that you created in the portion of code I gave you. I'm not exactly sure how you could choose the pdf printer because I never followed through with doing this in my own application. I was hoping someone else who knows for sure could pick up where I left off with you.
Jan 29 '14 #7
NeoPa
32,556 Expert Mod 16PB
Let's start with an explanation of where the data should come from for the three items that make up the name. Clearly they are not labels - as that would make not the slightest sense.

Newer versions of Access come with PDF printing built in. Let's also reveal the version you're working with so we have some idea of what is likely to be required and whether or not Access can handle it natively.
Jan 30 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Duy Nguyen | last post by:
how can I save an image file to database?
2
by: buran | last post by:
Dear ASP.NET Programmers, I am saving the tables of a dataset into an XML file. I want to save the XML file into the database, then retireve it as a dataset. I use the following code: ...
3
by: rodchar | last post by:
hey all, i was wondering once i save my xml file to a folder what would be my options to make sure that file is encrypted? i guess what would be some different ways to handle this is what, i (a...
3
by: needin4mation | last post by:
Hi, I have access 97. I can upgrade if I have to (but that will cost more money :)). If I want to read a row, parse that row, and then save the values to an HTML file, will VBA do that? Say I...
11
by: Thomas Magma | last post by:
I have a simple JavaScript application that will generate some text type data for the end user. Is it possible to have a button that will allow them to save this information to a text file? ...
0
by: Hexman | last post by:
Hello All, Its a bit more complicated than the subject line implies. A website that I use for information allows me to click on a link and their .PDF displays in IE's browser window.. Since...
7
by: shantanu | last post by:
Hi all i am trying to save a excel file as a tab delimited text file. can i do it some how? i using the code _sheet1.SaveAs(@"C:\PRP \PRPTemp.txt",Excel.XlFileFormat.xlTextWindows...
0
by: baldrex | last post by:
hello again, I have already gotten to the pdf file, however it hangs at the save as screen. What I am looking for is a snipet of code that will allow me to print to the pdf and auto save it to...
1
by: MichaelMelaku | last post by:
I am trying to save a txt file onto the client local drive (c:\Temp.txt) which will contain only xy coordinates generated by my web app. This txt file is to be consumed by another desktop app...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.