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 2045 Denburt 1,356
Recognized Expert Top Contributor
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 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...
|
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...
|
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...
|
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 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...
| |
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,
|
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
|
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.
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |