Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating Outlook e-mail from ACCESS

Status
Not open for further replies.

MDJ52

MIS
Mar 30, 2001
120
US
Below is a sample of my code. I run this code as a module in ACCESS2000. The problem I am having is that the code works fine first shot in the morning. The second time I run it, the system locks. I have tried this on both WIN2000 and WIN98.
I would like to develop this into a loop so we can send dozens of automatic e-mails. However with the lockup problem, this is not practical.

Function SendMessage(Optional AttachmentPath)

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

'Create the outlook session
Set objOutlook = CreateObject("Outlook.Application")

'Create the message
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
'Add the To recepient to the message
Set objOutlookRecip = .Recipients.Add([Forms]!
[forma]![frmSuba]![VendorEmail])
objOutlookRecip.Type = olTo

'Set Subject, Body and Importance of the message
.Subject = "Request for Info " & [Forms]![forma]!
[ReqNo]
.Body = "Please complete and return the attachment
before " & [Forms]![forma]![DueDate] & "." & vbCrLf &
vbCrLf & vbCrLf & vbCrLf & "Thank you." & vbCrLf & vbCrLf
.Importance = olImportanceHigh


'Add attachments to the message
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add
(AttachmentPath)
End If
'Kill attachment
Kill ("C:\My Documents\" + "info.doc")

.Send

' .Display

End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing


End Function
 
hi,

I can't exactly remember why, but quite a while ago we dropped declarations like outlook.application and changed to object. This implies a few restrictions, but as far as I can remember, causes lesser errors, so in your case you could change to s.t. like this:

Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object

'Create the outlook session
Set objOutlook = CreateObject("Outlook.Application")

'Create the message
Set objOutlookMsg = objOutlook.CreateItem(0)
'' this is one of the restrictions item must
'' be referred to by nr

With objOutlookMsg
'Add the To recepient to the message

.to = "xxx@yyy.com"
.attachments.Add "d:\base 0\test.gif"
...
.Send


End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing

don't know if it will do the trick, but it's worth the try..

the kid


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top