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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different e-mail recipients based on controls in forms. 2

Status
Not open for further replies.

cizmad

Technical User
Jul 6, 2005
14
US
I need to figure out a way to automate the sending of e-mails from a form that will be diverted to different recipients based on a value in one of the controls. (To one recipient if the value is under 500, another if the value is 500-1000, another if it is 1000-5000, etc). I'm pretty much a complete novice, and any and all suggestions would be appreciated.

-Ciz
 
Code:
Private Sub Command2_Click()
Dim olApp As Outlook.Application
Dim olMsg As MailItem
Dim strTo As String

Set olApp = New Outlook.Application
Set olMsg = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts).Items.Add(Outlook.olMailItem)

[COLOR=green]'me.Text0 is the control that is determining the recipient[/color]
Select Case Me.Text0
    Case Is < 500
        strTo = "mickey_mouse@disney.com"
    Case 500 To 999
        strTo = "donald_duck@disney.com"
    Case Else
        strTo = "uncle_bill@microsoft.com"
End Select

olMsg.To = strTo
olMsg.Subject = "Subject"
olMsg.HTMLBody = "Enter Message here " & "<p>" & _
        "Second line of message" & "<p>" & _
        "Third line of message"
        
olMsg.Save                      'Save message to defaulter folder
[COLOR=green]'olMsg.Send                     'Send message now[/color]

Set olMsg = Nothing
Set olApp = Nothing

End Sub
 
A problem that I'm sure reflects my extremely rudimentary knowledge of how this all works - where do I indicate the file to be attached? Because erm... I keep getting a missing reference notice, but it seems to otherwise be working like a charm.

Thanks again.

-Ciz
 
A starting point:
olMsg.Attachments.Add "\path\to\file.ext"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top