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

Save PDF and Email code error

43
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 2019
Denburt
1,356 Expert 1GB
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
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...
0
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...
8
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...
4
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
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...
5
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...
1
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......
4
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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,...
0
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...
0
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...

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.