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 - Private Sub Command114_Click()
-
Usage: SavePDFAndEmail "edwardphillips10@aol.com", Me.TourID
-
-
Function SavePDFAndEmail(EmailTo As String, UniqueIdentifier As Double)
-
'Add some error trapping
-
Dim strSource As String
-
-
Dim strTarget As String
-
Dim strFilename As String
-
'Save the PDF
-
DoCmd.OpenReport "rptInvoice", acViewNormal, , "[TourID] = " & TourID
-
'set values strSource = "C:\GhostPDF.pdf"
-
strTarget = CurrentDBDir & "Invoice" & TourID & ".pdf"
-
'copy it
-
FileCopy strSource, strTarget
-
-
'email it
-
Call CreateMail(EmailTo, "Invoice From D-Day Tours", "Invoice Attached", strTarget)
-
-
End Function Function CreateMail(ByRef astrRecip As Variant, _
-
strSubject As String, _
-
strMessage As String, _
-
Optional astrAttachments As Variant) As Boolean
-
'Code Found In comp.databases.ms-access
-
-
Dim objNewMail As Object
-
Dim varRecip As Variant
-
Dim varAttach As Variant
-
Dim blnResolveSuccess As Boolean
-
Dim golApp As Object
-
Dim initializeOutlook As Boolean
-
-
On Error GoTo CreateMail_Err
-
-
initializeOutlook = True
-
' Use the InitializeOutlook procedure to initialize global
-
' Application and NameSpace object variables, if necessary.
-
-
If golApp Is Nothing Then
-
If initializeOutlook = False Then
-
MsgBox "Unable to initialize Outlook Application or NameSpace object variables!"
-
Exit Function
-
End If
-
End If
-
-
Set golApp = CreateObject("Outlook.Application")
-
Set objNewMail = golApp.CreateItem(0)
-
-
With objNewMail
-
.Recipients.Add astrRecip
-
.Subject = strSubject
-
.Body = strMessage
-
.Attachments.Add astrAttachments
-
.Display
-
'.Send 'send it straight to the outbox if required
-
End With
-
-
CreateMail = True
-
-
Set golApp = Nothing
-
Set objNewMail = Nothing
-
-
CreateMail_End:
-
Exit Function
-
-
CreateMail_Err:
-
CreateMail = False
-
-
Select Case Err.Number
-
Case Is = 287
-
MsgBox "You clicked No to the Outlook security warning. " & _
-
"Please try again and click Yes to access e-mail" & _
-
"addresses to send your message. For more information," & _
-
"see the document at http://www.microsoft.com/office" & _
-
"/previous/outlook/downloads/security.asp. "
-
-
Case Is = -2009989111
-
MsgBox Err.Number & "" & Err.Description = "Reciepents Error"
-
-
Case Is = -1525219325
-
MsgBox Err.Number & " " & Err.Description = "Attachment Error"
-
-
Case Is = 438
-
MsgBox Err.Number & " " & Err.Description
-
-
Case Else
-
MsgBox Err.Number & "" & Err.Description
-
-
End Select
-
-
Resume CreateMail_End
-
End FunctionFunction CurrentDBDir() As String
-
Dim strDBPath As String
-
Dim strDBFile As String
-
-
strDBPath = CurrentDb.Name
-
strDBFile = Dir(strDBPath)
-
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
-
-
End Function
1 2019
The following might be Copy/paste errors if not you need to change the following lines: - Private Sub Command114_Click()
-
Usage: SavePDFAndEmail "edwardphillips10@aol.com", Me.TourID
-
Should be: - Private Sub Command114_Click()
-
Usage: SavePDFAndEmail "edwardphillips10@aol.com", Me.TourID
-
end sub
-
And the following needs some changes: -
End Function Function CreateMail(ByRef astrRecip As Variant, _
-
strSubject As String, _
-
strMessage As String, _
-
Optional astrAttachments As Variant) As Boolean
-
Change it to: - End Function
-
Function CreateMail(ByRef astrRecip As Variant, _
-
strSubject As String, _
-
strMessage As String, _
-
Optional astrAttachments As Variant) As Boolean
-
If you still have any errors we need to know specifically what the error message is then we can go further. Hope this helps.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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......
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: 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...
|
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...
| |