VBA code required

V

Vinod Lewis

I am creating a Leave application word form, where i need my users to click
the submit button and that sends an email out.

Application word 2007

This code works fine when the recepient clicks the submit button, the
recepient of the email is the one specified in the code.

ActiveDocument.SendForReview _
Recipients:="Your Email address here", _
Subject:="Your Subject here", _
ShowMessage:=False, _
IncludeAttachment:=True
MsgBox "Your Message has been sent!"

Help
====
In my form i have a combo box where the user selects a department in which
he is working, based on that department when the user clicks the submit
button. one email should go to the head of the selected department and one
email to the HR department. I need a code for that

Any help is appreciated.
 
D

Doug Robbins - Word MVP

You could use a Select Case ... End Select construction that evaluated the
..Result of the Drop Down Formfield and returned the appropriate email
address.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
V

Vinod Lewis

Thank you for your reply.

I dont know to write a code, so i need the code with the instruction.

The code which i have pasted is from one of the post.

Any help is appreciated
 
D

Doug Robbins - Word MVP

The .DropDown.Value for a dropdown formfield returns a number that coincides
with the order of the item that is select from the list. Therefore, for a
DropDown formfield that contained say the items Tom, Dick and Harry, you
could use:

Dim emaddress As String
Select Case ActiveDocument.FormFields("DropDown1").DropDown.Value
Case 1
emaddress = "(e-mail address removed)"
Case 2
emaddress = "(e-mail address removed)"
Case 3
emaddress = "(e-mail address removed)"
End Select
MsgBox emaddress

in a macro that ran on exit from the formfield. In your existing code, you
would then use

Recipients:= emaddress

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
V

Vinod Lewis

I really appreciate that you are trying to help me out. I am not able to do it.

Here is what i did,

I created a macro using your code. though i have a combo box in my form, i
changed to it to drop down

Dim emaddress As String
Select Case ActiveDocument.FormFields("DropDown1").DropDown.Value
Case 1
emaddress = "(e-mail address removed)"
Case 2
emaddress = "(e-mail address removed)"
End Select
MsgBox emaddress

This code runs if i assign to any form field exit.

Then you told me to change this in my submit code.

Recipients:= emaddress

I am doing something wrong, this macro and the submit button should combine
to get the results.

If you could write the complete code and tell where to place what, that
would be a great help.

waiting for an answer. Thanking you in advance.
 
D

Doug Robbins - Word MVP

Instead of using that code in a macro that run on exit from the combobox
(which is actually a DropDown type Formfield), incorporate it into the macro
that you now have.

The MsgBox line is not needed, it was only there to show you how the code
worked when run on exit from the Drop Down formField.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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