473,385 Members | 1,930 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,385 software developers and data experts.

How do you change the name of a pdf exported by access to a field name in the report?

269 256MB
I have a form. On the form I have a button that calls a report, saves it as a PDF, and attaches the PDF to Outlook in a blank email message. The button was created with the wizard in Access, as I'm not too handy with the code writing. I attach one report per email, and I use parameters to call the single record I want displayed in the report.
The problem is every report I attach takes on the exact same name--the name of the Access report("Transformer_Report.pdf"). So that we can differentiate all the files from each other, I want each report to take on the name from within a field on the report: "MENS#".

Here is the code the wizard wrote for me:

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnEmailReport_Click()
  2. On Error GoTo Err_btnEmailReport_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "Transformer_Report"
  7.     DoCmd.SendObject acReport, stDocName
  8.  
  9. Exit_btnEmailReport_Click:
  10.     Exit Sub
  11.  
  12. Err_btnEmailReport_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_btnEmailReport_Click
  15.  
  16. End Sub
Something tells me I ought to be able to play with the stDocName =... line and get my report named with the appropriate MENS# for each report I want to export. I can't find a simple way to do this. Can someone help me?

Keep in mind, my go-to reference is an "Access for Dummies" book--just so you know who you might be dealing with. HA!
May 29 '13 #1
9 4197
ADezii
8,834 Expert 8TB
Assuming MENS# is Unique for each Record:
Expand|Select|Wrap|Line Numbers
  1. stDocName = "Transformer_Report_" & Me![MENS#]
May 29 '13 #2
Seth Schrock
2,965 Expert 2GB
@ADezii
But isn't the DoCmd.SendObject command looking for a report with the name that is stored in stDocName? So if the name of the report is "Transformer_Report", then adding other text to it would cause an error because it can't find the object to attach.
May 30 '13 #3
DanicaDear
269 256MB
Seth might be on to something. When I tried that line of code, I get an error:
"Microsoft Office Access cannot find the object "Tranformer_Report_12345."
(12345 IS the correct MENS#).
May 30 '13 #4
Seth Schrock
2,965 Expert 2GB
If you really want to have the name the way you want it, then the only way that I know of is to create a PDF and save it with the name you want (done using the DoCmd.OutputTo command) and then attach it to the email (can be done with code). I actually do this in one of my databases where we need the report saved on the computer anyway. It is really cool to be able to do this, but it does take quite a bit of coding. If you want to go this way, let me know and I'll post what I have done. Also, are you using MS Outlook or CDO to send your email?
May 30 '13 #5
DanicaDear
269 256MB
I am using Outlook.

I have seen the complicated posts around the internet but their applications weren't close enough to mine that I could follow the code and adapt it to suit me. After 2 days of searching, I finally decided to ask here. I don't really write code, but thanks to some great interaction on Bytes I have learned to interpret it if it is simple enough. If you have a piece of code that is simple enough that you think I could figure it out and adapt it, I would be thrilled to look it over.

On another note---the PDF would not be required if I could put the items from the report directly into the email, just as text for example. In fact, this would be better, but I have never heard of this being done. Is that an alternative option?

To give a few more details...the items I put in the report are Tranformer serial numbers, weight, height, status, things of that nature. It's about 12 fields or so.

Thanks so much Seth (and ADezii too). I really appreciate your help and time.
May 30 '13 #6
ADezii
8,834 Expert 8TB
I use an approach very similr to Seth's in that I Output a Report to a specific Filename based on a Unique Value, in your case this would be [MENS#], in the Current Folder. This Reprt, in *.rtf Format, is now attached to an Outlook E-Mail. As also indicated by Seth, this can be a little complicated and using Automation Code.
May 30 '13 #7
Seth Schrock
2,965 Expert 2GB
If it is just the information that you are wanting, then you could make the text of the message be

Expand|Select|Wrap|Line Numbers
  1. Serial Number: 123xyz4
  2. Weight: 100 Lb.
  3. Height: 17 Inches
  4. Etc.
This would be simple code, but a lot of typing to do. You can even send it using Rich Text format (adds more typing). Here is an abbreviated version.

Expand|Select|Wrap|Line Numbers
  1. Public Sub SendEmail(SendTo As String, Subject As String)
  2.  
  3. Dim olApp As New Outlook.Application
  4. Dim olMailItem As Outlook.MailItem
  5. Dim strMsg As String
  6.  
  7. Set olMailItem = olApp.CreateItem(olMailItem)
  8.  
  9. strMsg = "<b>Serial Number:</b> " & Me.SerialNumber & "<br>" & _
  10.          "<b>Weight:</b> " & Me.Weight & "<br>" & _
  11.          "<b>Height:</b> " & Me.Height & "<br>"
  12.  
  13. With olMailItem
  14.     .To = SendTo
  15.     .Subject = Subject
  16.     .HTMLBody = strMsg
  17.     '.Send   'Uncomment if you want the email to be sent automatically
  18.     '.Display   'Uncomment if you want to view the email
  19. End With
  20.  
  21. End Sub
This uses early binding which requires a reference set to the Outlook reference. You just need to pass the email address the email gets sent to and the subject that you want. You can skip these if you just want to display the email and enter those things manually. To add the other fields just keep adding them to the strMsg variable. Currently I have the description text put in bold and the value in regular text.

Here is a list of the common tags you can put around the text to make it "rich":
Expand|Select|Wrap|Line Numbers
  1. <b>Text</b>   Bold
  2. <u>Text</u>   Underline
  3. <i>Text</i>   Italics
  4. <br>          Line break
May 30 '13 #8
zmbd
5,501 Expert Mod 4TB
Sticking with your wizard code; thus, trying to keep things simple, the basic format for the command you are using is:

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

Note that there are "Subject" and MessageText parameters that can be used.

Takeing the concept from ADezii for the name and using it for the subject of the email (and/or if you like we can add it to the message text - which is what I've done here) we can do the following:

(Please note: The following may have typos... however it compiled on my PC)
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnEmailReport_Click() 
  2. On Error GoTo Err_btnEmailReport_Click
  3. '
  4.     Dim stDocName As String
  5.     Dim stSubject As String
  6.     Dim stMessageText As String
  7.  
  8. '
  9.     stDocName = "Transformer_Report"
  10.     stSubject = "Transformer_Report_" & Me![MENS#]
  11.     stMessageText = "Transformer_Report_" & Me![MENS#]
  12. '
  13. DoCmd.SendObject objecttype:=acReport, ObjectName:=stDocName, subject:=stSubject, MessageText:=stMessageText
  14. '
  15. Exit_btnEmailReport_Click:
  16.     Exit Sub
  17. '
  18. Err_btnEmailReport_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_btnEmailReport_Click
  21.  
  22. End Sub 
Not exactly what you want; however, very straight forward.
If you truely want to change the report name I'll work on that too.

-z
May 30 '13 #9
zmbd
5,501 Expert Mod 4TB
BTW: Which version of Access?
May 30 '13 #10

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

Similar topics

3
by: Louis | last post by:
Is there a switch or a setting in Access so that a group by query doesn't return a field name SumOf(original field name)? Especially when you chain multiple queries together you'd get...
2
by: LoopyNZ | last post by:
Hi, (Access 97) I'm creating a query (QRY_SUMMARY) to join a query (QRY) to itself (QRY_1). I'm returning QRY.* and selected fields from QRY_1. With each field (field_name) I return from...
5
by: David | last post by:
Hi I seem to be getting nowhere with this. I am opening a form which will be used to input Notes into different fields in a table. My problem is changing the unbound field name to the field name...
1
by: Greg | last post by:
I have an Access db (actually, about 60 of them) that has a table with a field named Q#. This table gets read into a dataset. In the dataset, the field is also called Q#. But when I try to update...
0
by: Maurizio | last post by:
if i compile this code: using System; using System.Reflection; using System.EnterpriseServices; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; public enum...
5
by: effendi | last post by:
I am trying to write a simple routine multiplying one value of a field to another. i.e cost1 multiple by cost2.. But since I have many lines of these, I want to write a function by accessing the...
1
by: LOCAFO | last post by:
I have a form that I'm trying to modify. Code uses html and javascript. The form has the the field name txtAcctType and the 3 options are checking, savings and Money Market. If checking is...
11
by: Tempalli | last post by:
I am using M.S.Access as backend database and able to add records from Excel but not able to Edit & Update the specific record from M.s Access with reference to cell value given in excel. Kinldy help...
2
by: shalskedar | last post by:
I 've created Report in Ms access which contains subform.The field value in the report is retrieved from the subform.When this report is exported,it shows the error as The expression you entered has...
8
TheSmileyCoder
by: TheSmileyCoder | last post by:
I have a field tx_Value which I want to use in some Detail_Format event. However if I try using: Me.tx_Value I get an error msg "Method or Data Menber not found" If I try either of these...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.