|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Hello,
I'm trying to set up some code which automatically sends an email. The code is in a module which I want to call from somewhere else (the event procedure of a button click). Firstly, how do I call a module from somewhere (I've tried the usual ways but no luck)? Also, when I compile the code I get a 'user defined type not defined' error on the first line (Dim objOutlook...). I don't understand that because I AM defining it! Any ideas? Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath, Optional emailaddress As String, Optional emailsubject As String, Optional emailbody As String) 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 recipient(s) to the message. emailaddress = "Hearn Paula (5HQ) Bolton PCT" Set objOutlookRecip = .Recipients.Add(emailaddress) objOutlookRecip.Type = olTo ' Add the CC recipient(s) to the message. 'Set objOutlookRecip = .Recipients.Add("Cowie Alan (RMM) CH Bolton") 'objOutlookRecip.Type = olCC ' Set the Subject, Body, and Importance of the message. emailsubject = "Clinical Audit Test" emailbody = "Email Test for Clinical Audit System" .Subject = emailsubject .Body = emailbody & vbCrLf & vbCrLf .Importance = olimportancehigh 'High importance ' Add attachments to the message. If Not IsMissing(AttachmentPath) Then Set objOutlookAttach = .Attachments.Add(AttachmentPath) End If ' Resolve each Recipient's name. For Each objOutlookRecip In .Recipients objOutlookRecip.Resolve Next ' Should we display the message before sending? If DisplayMsg Then .Display Else .Save .Send End If End With Set objOutlook = Nothing End Sub |
|
#2
|
|||
|
|||
|
One thing, you'll need to add a reference to the Outlook application in your VB project.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#3
|
|||
|
|||
|
How and where do I do that?
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Automatic Emailing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|