Outlook Email To email address dependent on dropdown value

W

Worsty

I have the vba code in my word 2003 form to send an email to a
specific address etc.

What I want to do is depending upon the value of a specific dropdown
field send to a different email address.

So, if the value is 1 then send to (e-mail address removed) but if the value
is 2 then sent to (e-mail address removed).

I've looked everywhere on this group and can't find an answer.

Could someone help me out please.

thanks so much you guys are great!
 
G

Graham Mayor

The following should work

Sub Send_As_Mail_Attachment()
' send the document as an attachment _
in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim iChk As Integer

On Error Resume Next
'Get the result from the dropdown field
iChk = ActiveDocument.FormFields("Dropdown1").Result
'Prompt the user to save the document
ActiveDocument.Save

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
If iChk = 1 Then .To = "(e-mail address removed)"
If iChk = 2 Then .To = "(e-mail address removed)"
.Subject = "This is the subject"
'Add the document as an attachment, you can use the _
.displayname property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, _
Type:=olByValue, DisplayName:="Document as attachment"
.Display
End With

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
W

Worsty

The following should work

Sub Send_As_Mail_Attachment()
' send the document as an attachment _
in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim iChk As Integer

On Error Resume Next
'Get the result from the dropdown field
iChk = ActiveDocument.FormFields("Dropdown1").Result
'Prompt the user to save the document
ActiveDocument.Save

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, start it from code
If Err <> 0 Then
   Set oOutlookApp = CreateObject("Outlook.Application")
   bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

    With oItem
        If iChk = 1 Then .To = "(e-mail address removed)"
        If iChk = 2 Then .To = "(e-mail address removed)"
        .Subject = "This is the subject"
    'Add the document as an attachment, you can use the _
    .displayname property
    'to set the description that's used in the message
        .Attachments.Add Source:=ActiveDocument.FullName, _
        Type:=olByValue, DisplayName:="Document as attachment"
        .Display
     End With

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>











- Show quoted text -

*****************************************

Graham,
On another note, is there a way to "HIDE" a Word form field or Word
dropdown form field based upon another form field value? I've been
looking through the group entries and don't see anything like that on
here.

Thanks in advance
 
G

Graham Mayor

The following will hide Text1 when the value of Dropdown1 is 1 and display
it when it is anything else

With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect Password:=""
End If
If .FormFields("Dropdown1").Result = 1 Then
.FormFields("Text1").Result = ""
.FormFields("Text1").Range.Font.Hidden = True
.FormFields("Text2").Select
Else
.FormFields("Text1").Range.Font.Hidden = False
.FormFields("Text1").Select
End If
.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=""
End With
 
W

Worsty

The following will hide Text1 when the value of Dropdown1 is 1 and display
it when it is anything else

With ActiveDocument
    If .ProtectionType <> wdNoProtection Then
        .Unprotect Password:=""
    End If
    If .FormFields("Dropdown1").Result = 1 Then
        .FormFields("Text1").Result = ""
        .FormFields("Text1").Range.Font.Hidden = True
        .FormFields("Text2").Select
    Else
        .FormFields("Text1").Range.Font.Hidden = False
        .FormFields("Text1").Select
    End If
    .Protect _
    Type:=wdAllowOnlyFormFields, _
    NoReset:=True, _
    Password:=""
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>




- Show quoted text -

Thanks Graham for all your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top