A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Programmatically sending email from Access



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 5th 06, 06:08 PM posted to microsoft.public.outlook.program_vba
scariharry
external usenet poster
 
Posts: 1
Default Programmatically sending email from Access

Well with Sue's help I found a solution to the security dialogs that pop up
when I tried to send email out of Access to Outlook.


Two prong approach using both Access and Outlook in VBA

In Access:

Option Compare Database
Option Explicit
Public Sub SendMessage1()

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookAtt As Outlook.Attachment
Dim strBody As String

Set objOutlook = New Outlook.Application 'Create the Outlook session
Set objOutlookMsg = objOutlook.CreateItem(olMailItem) 'Create message

With objOutlookMsg
.To = "Dist List" 'Send To:
.CC = "" 'CC:
.Subject = "This is a Test..... this is only a test -+agmm" 'Subject:
'Msgtxt: Body is set below attachment line....
strBody = "Like I said, it's just a test."
strBody = strBody & vbCrLf & "Still testing"
strBody = strBody & vbCrLf & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'Importance
'Attachments
Set objOutlookAtt = .Attachments.Add("[path]")
strBody = strBody & vbCrLf & "That is an attachment" & vbCrLf & vbCrLf
.Body = strBody
.Save
End With
End Sub


In Outlook:
Public WithEvents sndDraft As Outlook.Items


Public Sub Application_Startup()

Set sndDraft = Outlook.Session.GetDefaultFolder(olFolderDrafts).I tems

End Sub


Private Sub sndDraft_ItemAdd(ByVal Item As Object)

Dim objSubT As String
objSubT = Right(Item.Subject, 6)

If TypeName(Item) = "MailItem" Then
If objSubT = "-+agmm" Then

Dim objSub As String
Dim objSubF As String
Dim subLen As Integer
objSub = Item.Subject
subLen = Len(objSub)
objSubF = Left(objSub, (subLen - 6))

Item.Subject = objSubF
Item.Send

End If
End If

End Sub

This works with not a single security blurb.....

Thanks Sue
Ads
 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically Export Outlook Mail to Microsoft Access LDMueller Outlook and VBA 4 June 13th 06 03:54 PM
have to restart access after sending one email Tony Epton Outlook and VBA 1 May 6th 06 08:31 PM
have to restart access after sending one email Tony Epton Outlook and VBA 0 May 6th 06 05:48 PM
Programmatically send Email text containing hyperlinks from Access momotaro Outlook and VBA 2 May 4th 06 09:44 PM
Sending Email With Outlook Or Even Web Access [email protected] Outlook - General Queries 1 March 22nd 06 05:11 PM


All times are GMT +1. The time now is 08:17 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.