Some Access to Oulook stuff

Mike375

Registered User.
Local time
Tomorrow, 05:08
Joined
Aug 28, 2008
Messages
2,542
This might be of use to some others. I have been playing to get this right through the night, morning in Australia.:)

The following is inserting the contents and format of a Word doc in the body of the email. At the top of the Word doc is a bookmark and it sticks in the contents from a text box. I also down loaded the Yes Pro to fix the Outlook security pop up box. I just tested it by emailing myself 30 times in one run. I put the code in a module and then a GoToNextRecord etc. I almost wore the internet out trying to find a way to avoid the yes Pro but I only found one and it was not reliable. With the Yes No it just wizzed straight through the 30 records.

You need reference to Microsoft Word and Outlook libraries.

Hope it is of use someone.

Dim OutMail As Object
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
Dim wd As Word.Application
Dim doc As Word.Document
Dim WordRange As Word.Range
Dim Itm As Object
Dim ID As String
Dim blnWeOpenedWord As Boolean
On Error Resume Next
Set wd = GetObject(, "Word.Application")
If wd Is Nothing Then
Set wd = CreateObject("Word.Application")
blnWeOpenedWord = True
End If
Set doc = wd.Documents.Open _
(FileName:="c:\Letters\SoftwareSolutions3.doc")
Set WordRange = doc.Goto(What:=wdGoToBookmark, Name:="a1")
WordRange.InsertBefore Nz([Forms]![PrintAndClose]![Notes], "")
doc.wdSaveChanges
Set Itm = doc.MailEnvelope.Item
With Itm
.To = Forms!PrintAndClose!EMStore
.Subject = [Forms]![PrintAndClose]![Text446]
.Save
ID = .EntryID
End With
Set Itm = Nothing
Set Itm = Outlook.Application.Session.GetItemFromID(ID)
Itm.Send
doc.Close wdDoNotSaveChanges
If blnWeOpenedWord Then
wd.Quit
End If
Set doc = Nothing
Set Itm = Nothing
Set wd = Nothing
 

Users who are viewing this thread

Back
Top Bottom