By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,316 Members | 2,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,316 IT Pros & Developers. It's quick & easy.

Creating EMAIL from VBA (behind a form)

P: n/a
I know that it is possible to generate an email letter and send it from
VBA behind a form. I've done that. However, is it possible to create a
DRAFT email letter and leave it in the Drafts folder (in Microsoft
Outlook)? If it is possible, would you share the source code with me?

Thanks.

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
hello sueB,

i have an access application that reads outlook draft folder contents
and list it in a listbox-control to expose it to the users, then they
can doble-click one item and edit it that way.

well i think that what you have to do is to set an instance of a new
mail-item and instead of send it just save it to the draft folder.

does it help??.

+regards,

Susan Bricker wrote:
I know that it is possible to generate an email letter and send it from
VBA behind a form. I've done that. However, is it possible to create a
DRAFT email letter and leave it in the Drafts folder (in Microsoft
Outlook)? If it is possible, would you share the source code with me?

Thanks.

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***


Nov 13 '05 #2

P: n/a
On Tue, 25 Oct 2005 09:57:07 GMT, Susan Bricker <sl*****@verizon.net>
wrote:
I know that it is possible to generate an email letter and send it from
VBA behind a form. I've done that. However, is it possible to create a
DRAFT email letter and leave it in the Drafts folder (in Microsoft
Outlook)? If it is possible, would you share the source code with me?


Public Sub SendMailWithAttachment( _
strTo As String, _
strAttachmentFiles As String, _
Optional strSubject As String = "", _
Optional strBodyText As String = "", _
Optional bolQuitOutlook As Boolean = False, _
Optional bolSendAsDraft As Boolean = True)

Dim OL As Object
Dim OLNS As Object 'Outlook.NameSpace
Dim MailFolder As Object 'Outlook.MAPIFolder
Dim MyMail As Object 'Outlook.MailItem
Dim varAttachments As Variant
Dim I As Integer

varAttachments = Split(strAttachmentFiles, Chr$(0))
Set OL = CreateObject("Outlook.Application")
Set OLNS = OL.GetNamespace("MAPI")
If bolSendAsDraft = True Then
Set MailFolder = OLNS.GetDefaultFolder(16)
Else
Set MailFolder = OLNS.GetDefaultFolder("Inbox")
End If
Set MyMail = MailFolder.Items.Add

With MyMail
.To = strTo
.Subject = strSubject
.Body = strBodyText
For I = 0 To UBound(varAttachments)
If CStr(varAttachments(I)) <> "" Then _
.Attachments.Add CStr(varAttachments(I)), _
1, _
I + 1
Next
.Recipients.ResolveAll
.Save
If bolSendAsDraft = False Then
.Send
End If
End With
If bolQuitOutlook = True Then OL.Quit
Set MyMail = Nothing
Set MailFolder = Nothing
Set OLNS = Nothing
Set OL = Nothing
End Sub
--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.