Word 2003 - how do I email to specific recipient?

L

Lorrie Burns

I have a userform that populates a word form with the user's responses when
they click "Submit" on the userform. So far, so good, but the other thing I
need to have happen when the submit button is clicked is to have that word
form emailed to one recepient as an attachment and then close without saving.
To take it a step further, I would like to allow the user to print and/or
save the form by clicking a different command button. Also, how do I
automatically have the "Disable/Enable Macro dialog box set to "Enable" just
for this document?
Anyone know the code for this?
 
D

Doug Robbins - Word MVP

See the article "How to send an email from Word using VBA" at:

http://www.word.mvps.org/FAQs/InterDev/SendMail.htm

To do the Print Save thing, from a button on the userform, you are going to
have to replicate the population routine and the best way to have that done
without it causing problems is to have document variables set to the data
that is entered into the form and use Docvariable fields in the document to
display the data. You will need to incorporate commands in your code to
update the Docvariable fields so that they display the data that is entered
into the variables. If such a routine is run twice, it doesn't matter, but
you will get into all sorts of strife if you are populating bookmarks with
the data entered into the form.

As you will be needing to keep the userform active to allow any or all of
your buttons (Save, Print, Submit) to be used, you will need another button
for "finished".

On the Disable/Enable macro business, if the user form is in a template that
is stored in the templates folder, it will be trusted so the issue will not
arise.

For very good reasons, it is not possible to use code to vary the
Disable/Enable macros setting.


--
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
 
L

Lorrie Burns

Thanks. I've decided not to allow the user to print and/or save the
document, I just want to have it email to a recipient. However, when I put
the required code in for a routing slip and then click the submit button on
my userform, it gives an error and wants to shut down Word. Any idea what
the problem could be?
 
D

Doug Robbins - Word MVP

What does the error message say?

You probably also need to show us the complete code.

--
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
 
L

Lorrie Burns

Thank you.

Here is the vb error:
--
Run-time error '-214747848 (80010108)':
Automation error
The object invoked has disconnected from its clients.
--
This is the code in my command button:

Private Sub CommandButton1_Click()
With ActiveDocument
ActiveDocument.FormFields("Text1").Result = TextBox1
ActiveDocument.FormFields("Text2").Result = TextBox2
ActiveDocument.FormFields("Text3").Result = TextBox3
ActiveDocument.FormFields("Text4").Result = TextBox4
ActiveDocument.FormFields("Text5").Result = TextBox5
ActiveDocument.FormFields("Text6").Result = TextBox6
End With

Dim indx As Integer
For indx = 1 To 20 ' or as many as you need
ActiveDocument.FormFields("Check" & indx).CheckBox.Value _
= Me.Controls("OptionButton" & indx).Value
Next indx

ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "Test"
.AddRecipient "(e-mail address removed)"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route

UserForm2.Hide

End Sub
--
 
D

Doug Robbins - Word MVP

The only version that I have to check this in at the moment is 2007 and I am
getting a different error, even with the following stripped down version of
the code:

If ActiveDocument.HasRoutingSlip = True Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If

so I have asked some colleagues to point out the obvious to me (aka "what am
I doing wrong")

I need to get that solved first.

--
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
 
D

Doug Robbins - Word MVP

I am sorry, but I cannot test this as I am advised that the .HasRoutingSlip
method has been deprecated in Word 2007 and the only other machine on which
I could test is connected to a system that uses Lotus Notes that does not
support routing.

I suggest therefore that you start a new thread to deal with this problem as
there is a better chance then of involving others who may be able to help
you.
 

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