Hullo Everybody
I am trying to send a email from WITHIN Access 2000 with a report
attached that is generated WITHIN Access in the normal way, but all the
help examples I have seen uses an external file like C:\test.txt
I have been using:
DoCmd.SendObject acReport, stDocName, acFormatRTF,
But when the message body is more than 70 characters long (random), it
craps out, and it seems that the general opinion is that SendObject is
too unreliable to use for a runtime application.
So I have now moved to the method below which almost works except for 2
things. .........What I need to know is how to:
1.Add an attachment of one of the internal reports (rptOrderEmail) to
the email.
2. Supress the handling form with the message "Another program is
trying to access your Inbox" a pain.
Thanks in Advance
Bob
Private Sub CmdEmail_Click()
On Error GoTo Error_Handler
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strDocName As String
Dim rptInvoiceEmail As Report_rptOrderEmail
strDocName = "rptOrderEmail"
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = Me.txtSupplierPrimaryEmail
.Subject = Me.txtSubject
.Body = Me.MemoSupplierNotes
Set objOutlookAttach = .Attachments.Add(strDocName)
.Send
'.ReadReceiptRequested
End With
Exit_Here:
Set objOutlook = Nothing
Exit Sub
Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here
End Sub 9 1838
Option Compare Database
Option Explicit
Dim mGetDPG As String
Dim mGetRecipients As String
Dim mOutlook As Outlook.Application
Dim mOutlookMsg As Outlook.MailItem
Dim mOutlookRecip As Outlook.Recipient
Dim mOutlookAttach As Outlook.Attachment
Dim mstrAddRecipients As String
Dim mAttachmentPath As String
Dim mSession As Outlook.NameSpace
Dim myPathToLookForFile as string
Dim i As Integer
Dim strRemovePath As String
Dim frm As New Form_frmEmailSend
Public Function CreateMail(ByRef astrRecip As Variant, ByRef
astrRecipCC As Variant, strSubject As String, strMessage As String,
Optional astrAttachments As Variant) As Boolean
' This procedure illustrates how to create a new mail message
' and use the information passed as arguments to set message
' properties for the subject, text (Body property), attachments,
' and recipients.
Dim ParaA(5) As String
Dim strSearchCriteria As String
Dim objNewMail As Outlook.MailItem
Dim varRecip As Variant
Dim varAttach As Variant
Dim blnResolveSuccess As Boolean
Dim golApp As Outlook.Application
Dim initializeOutlook As Boolean
Dim fs
Set fs = Application.FileSearch
initializeOutlook = True
On Error GoTo CreateMail_Err
' 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 = New Outlook.Application
Set objNewMail = golApp.CreateItem(olMailItem)
With objNewMail
' For Each varRecip In astrRecip
.Recipients.Add astrRecip
.CC = astrRecipCC
' Next varRecip
blnResolveSuccess = .Recipients.ResolveAll
With fs
..
fs.LookIn = myPathToLookForFile
' Can include full name or part of the file name for difference
months, times, etc,
strSearchCriteria = "*".rtf"
' .FileName = "*.rtf"
.filename = strSearchCriteria
If .Execute > 0 Then
'
For i = 1 To .FoundFiles.Count
ParaA(i) = fs.FoundFiles(i)
objNewMail.Attachments.Add ParaA(i),
olByValue, i
Next i
End If
End With
.Subject = strSubject
.Body = strMessage
If blnResolveSuccess = True Then
' .Send
Else
' MsgBox "Unable to resolve all recipients. Please check " _
' & "the names."
.Display
End If
End With
CreateMail = True
CreateMail_End:
Exit Function
CreateMail_Err:
CreateMail = False
' there is some code I seen, were by the prompt warning can be bypass,
click oK automatic.
Select Case Err.Number
Case Is = 287
MsgBox "You clicked No to the Outlook security warning. " & _
"Return the procedure 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 Function
Public Property Get GetDPG() As String
GetDPG = mGetDPG
End Property
Public Property Let GetDPG(ByVal vNewValue As String)
mGetDPG = vNewValue
End Property
Public Property Get GetRecipients() As String
GetRecipients = mGetRecipients
End Property
Public Property Let GetRecipients(ByVal vNewValue As String)
mGetRecipients = vNewValue
End Property
Private Sub Class_Initialize()
'Set mGetDPG = Nothing
'Set mGetRecipients = Nothing
Set mOutlook = Nothing
Set mOutlookMsg = Nothing
Set mOutlookRecip = Nothing
Set mOutlookAttach = Nothing
'Set mstrAddRecipients = Nothing
'Set mAttachmentPath = Nothing
Set mSession = Nothing
End Sub
Thanks loringdo
I was beginning to think it was impossible
bob
Bob:
To suppress the Outlook Security Warning, you can download & install
the freeware called Express ClickYes v1.2. I've utilized it for quite
some time, and have had no issues.
Here's where you can get it: http://contextmagic.com/express-clickyes/
HTH,
Jana
Hi Jana
Thats an interesting piece of kit. I was hoping to build some sort of a
Suppresser into the software, and update the existing userbase with a
new MS Access front end. However, it might be an idea to tell them to
get this software.
Thaks for the suggestion
Bob
Hi Bob:
You're welcome!
Yes, bypassing Outlook Security on your own is going to be rough. I
figure why reinvent the wheel? Since this is freeware and allows the
user to decide when to use it & when not to, it does exactly what I
need. Also, you can turn it on in the middle of a process without any
grief.
Happy coding,
Jana
Hi Jana
Thanks for your help
THe problem with this that if you bypass Outlook Security for the
program that you want it for ie my Access.mde, you are also bypassing
Outlook Security for Malware, spyware etc.
Regards Bob
Jana thanks for the link, I been reading a lot on Security Warning
utility. Better yet they give some code to use also,
Thanks for sharing,
loringdo
You're welcome, Bob. The software has the ability to be turned on and
off, so I only enable it when I'm actually running code that sends out
emails. Otherwise, it's disabled, thereby minimizing the opportunity
for Malware, Spyware, etc.
It's not a perfect solution, but it accomplishes what you're looking
for.
Jana This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Wald |
last post by:
Hello group,
I've got a script here that sends emails with an attachment to
an email address that is retrieved from an html form. The
email sending code is include below.
The problem: when...
|
by: abracad |
last post by:
I'd like to add a form that will email a file attachment to me.
Can anyone recommend a decent free script?
Thanks
|
by: Paul Schmidt |
last post by:
Dear list:
I am new to python, and I am trying to figure out the short answer on
something.
I want to open a POP3 mailbox, read the enclosed mail using the POP3
module, , and then process it...
|
by: Martin Körner |
last post by:
Hi NG,
I am using email module for creating mails with attachment (and then
sending via smtplib).
If the name of the attachment file is longer than about 60 characters
the filename is wrapped...
|
by: morphex |
last post by:
Hi,
I have an email that's in the utf-8 encoding, and I'm getting this
error message when I try to send it using smtplib:
* Module smtplib, line 688, in sendmail
* Module smtplib, line 485,...
|
by: =?Utf-8?B?SHVnaA==?= |
last post by:
Hi There,
I use follow code to send email inside VB.NET 2005. It does not work well.
Error message of "Failure sending email" would occue. However, email was
sent out sometimes. I am confused...
|
by: erikcw |
last post by:
Hi all,
I'm trying to extract zip file (containing an xml file) from an email
so I can process it. But I'm running up against some brick walls.
I've been googling and reading all afternoon, and...
|
by: jambonjamasb |
last post by:
Hi
I have two tables:
email_tbl
Data_table
Data table is is used to create a Form
Data_form
|
by: tourerukcom |
last post by:
Hi
i wonder if any one can help. I have script that that sends a email
with mulitple attachments. It seems to work fine as i get the email
with the attachments on. But other people i send it to...
|
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$) {
}
...
|
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: 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...
|
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: 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...
|
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: 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...
|
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...
| |