473,803 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save PDF and Email code error

43 New Member
Hi All,

I have been using this guide http://www.compasscomputing.co.uk/co...DFandEmail.htm to create a command button that automatically saves and e-mails your report and have tried to edit the code, as below (the original code is on his website) but get a load of error messages.

There are only a few bits that need editing (about 6 or 7 little bits) but I still get loads of error messages and if anyone can help, I would be really grateful.

To give you some background info, I would like the report to always be emailed to ***Address Removed by Mod***@aol.com (and no one else), the unique field of the report for the filter if that is necessary is 'TourID'. The name of the report is 'rptInvoice' and I would like the command button to be on 'frmTours'.

i am not sure if I have even gone about it the right way but any help would be greatly appreciated.

Many thanks in advance and best wishes

Edd

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command114_Click()
  2. Usage: SavePDFAndEmail "edwardphillips10@aol.com", Me.TourID
  3.  
  4. Function SavePDFAndEmail(EmailTo As String, UniqueIdentifier As Double)
  5. 'Add some error trapping
  6. Dim strSource As String
  7.  
  8. Dim strTarget As String
  9. Dim strFilename As String
  10. 'Save the PDF
  11. DoCmd.OpenReport "rptInvoice", acViewNormal, , "[TourID] = " & TourID
  12. 'set values strSource = "C:\GhostPDF.pdf"
  13. strTarget = CurrentDBDir & "Invoice" & TourID & ".pdf"
  14. 'copy it
  15. FileCopy strSource, strTarget
  16.  
  17. 'email it
  18. Call CreateMail(EmailTo, "Invoice From D-Day Tours", "Invoice Attached", strTarget)
  19.  
  20. End Function Function CreateMail(ByRef astrRecip As Variant, _
  21. strSubject As String, _
  22. strMessage As String, _
  23. Optional astrAttachments As Variant) As Boolean
  24. 'Code Found In comp.databases.ms-access
  25.  
  26. Dim objNewMail As Object
  27. Dim varRecip As Variant
  28. Dim varAttach As Variant
  29. Dim blnResolveSuccess As Boolean
  30. Dim golApp As Object
  31. Dim initializeOutlook As Boolean
  32.  
  33. On Error GoTo CreateMail_Err
  34.  
  35. initializeOutlook = True
  36. ' Use the InitializeOutlook procedure to initialize global
  37. ' Application and NameSpace object variables, if necessary.
  38.  
  39. If golApp Is Nothing Then
  40. If initializeOutlook = False Then
  41. MsgBox "Unable to initialize Outlook Application or NameSpace object variables!"
  42. Exit Function
  43. End If
  44. End If
  45.  
  46. Set golApp = CreateObject("Outlook.Application")
  47. Set objNewMail = golApp.CreateItem(0)
  48.  
  49. With objNewMail
  50. .Recipients.Add astrRecip
  51. .Subject = strSubject
  52. .Body = strMessage
  53. .Attachments.Add astrAttachments
  54. .Display
  55. '.Send 'send it straight to the outbox if required
  56. End With
  57.  
  58. CreateMail = True
  59.  
  60. Set golApp = Nothing
  61. Set objNewMail = Nothing
  62.  
  63. CreateMail_End:
  64. Exit Function
  65.  
  66. CreateMail_Err:
  67. CreateMail = False
  68.  
  69. Select Case Err.Number
  70. Case Is = 287
  71. MsgBox "You clicked No to the Outlook security warning. " & _
  72. "Please try again and click Yes to access e-mail" & _
  73. "addresses to send your message. For more information," & _
  74. "see the document at http://www.microsoft.com/office" & _
  75. "/previous/outlook/downloads/security.asp. "
  76.  
  77. Case Is = -2009989111
  78. MsgBox Err.Number & "" & Err.Description = "Reciepents Error"
  79.  
  80. Case Is = -1525219325
  81. MsgBox Err.Number & " " & Err.Description = "Attachment Error"
  82.  
  83. Case Is = 438
  84. MsgBox Err.Number & " " & Err.Description
  85.  
  86. Case Else
  87. MsgBox Err.Number & "" & Err.Description
  88.  
  89. End Select
  90.  
  91. Resume CreateMail_End
  92. End FunctionFunction CurrentDBDir() As String
  93. Dim strDBPath As String
  94. Dim strDBFile As String
  95.  
  96. strDBPath = CurrentDb.Name
  97. strDBFile = Dir(strDBPath)
  98. CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
  99.  
  100. End Function
Apr 15 '07 #1
1 2045
Denburt
1,356 Recognized Expert Top Contributor
The following might be Copy/paste errors if not you need to change the following lines:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command114_Click()
  2. Usage: SavePDFAndEmail "edwardphillips10@aol.com", Me.TourID
  3.  
Should be:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command114_Click()
  2. Usage: SavePDFAndEmail "edwardphillips10@aol.com", Me.TourID
  3. end sub
  4.  
And the following needs some changes:
Expand|Select|Wrap|Line Numbers
  1. End Function Function CreateMail(ByRef astrRecip As Variant, _
  2. strSubject As String, _
  3. strMessage As String, _
  4. Optional astrAttachments As Variant) As Boolean
  5.  
Change it to:

Expand|Select|Wrap|Line Numbers
  1. End Function 
  2. Function CreateMail(ByRef astrRecip As Variant, _
  3. strSubject As String, _
  4. strMessage As String, _
  5. Optional astrAttachments As Variant) As Boolean
  6.  
If you still have any errors we need to know specifically what the error message is then we can go further. Hope this helps.
Apr 20 '07 #2

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

Similar topics

4
3447
by: WJA | last post by:
I'm probably missing something here but I can't understand the following. When 2 users try to save a record with the same primary key (a number field), the first record saves as expected, but the second does not produce an error. The "Save" button uses "Docmd.Save" to save the record. If I insert "Me.Dirty = False" before "Docmd.Save" an error is produced. Why doesn't "Docmd.Save" produce an error but instead silently fails to save the...
0
41184
by: I Decker | last post by:
Hi all, Hope this is the right group. I am writing a program in c# to open create an excel document, enter some data, save it and then email it as an attachment. I have successfully created an excel document which the user can see (at this stage of development) and passed some data to it. I then used the savas method to save the file. Again this seems to work as the file is created. However once I close the excel file and try and...
8
3715
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
4
6269
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
5
2665
by: C Watson | last post by:
Hi, I'm wondering if anyone can help me with AJAX in ASP.NET 1.1. I have a very specific feature that I would like to use it for. I have a rather long form that the users use to enter data during a phone call with a client. Since it's long, I put six Save buttons down the length of the form and asked the users to save often. When they click the Save buttons, the data is saved to a central database and a text label is changed to say...
5
1958
by: hp_1981 | last post by:
Hi Is there anyway avoiding users to save my web pages? this idea came to my mind when I tried to save a web page, but in the middle of saving progress something like the following error occurred: "unable to save the page...". on the other hand, once, I saved a web page successfully, but when I opened it the characters were completely unreadable. unfortunately I can't remember the url now but if you know any way to restrict users,
1
3478
by: =?Utf-8?B?UmFqdSBB?= | last post by:
hi, Can any one help me .. how to save outlook attachment file in C# windows Application... i m able to read the filename but i dont know how to save the attachment file to my local Drives... pls send me the code r give me any idea ... i have used filecopy and saveasfile method also but i get the error... Regards RAJ
4
6147
by: Logician | last post by:
I am running on my PC Windows Forms to collect data from websites, including images. I hit a problem with images and javascript, and I would appreciate any help. The current code fails with a copy error. My Internet connected PC is not the development machine, so I cannot debug on that PC and my other PC has no Internet connection. So I cannot debug using .NET as normal.
2
3031
by: chike_oji | last post by:
Please can someone help me. I am writing a web application, that allows for the upload of an excel sheet into the database. I have an upload button and a save button. The upload button allows for the retrieval of the excel data into a DataTable, which is bound to a GridView for previewing before saving to the Database. But, whenever I click on the save button, I lose the DataTable's data, so I lose the data I want to save to the...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.