Button to email a user form.

  • Thread starter Mike MrMunka Gillingham
  • Start date
M

Mike MrMunka Gillingham

Ok, I'm having a terrible time doing this. Nothing is working like I need.

I have a few text box fields to be filled out and a simple button at the
bottom of the page to click on and have the document emailed to one email
address.

The code I have dug up here is using a routing slip or something and every
time I send the form, it attaches another email address to the TO: field. Now
I have like 12 of the same address all listed each time I send a new email
using this form.

Here's the code.

Private Sub CommandButton1_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "New subject goes here"
.AddRecipient "(e-mail address removed)"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub


The form can be mailed as an attachment, I'm just having a hell of a time
getting what seems to be a simple task to work properly. Thanks in advance.

Mike
 
J

Jean-Guy Marcil

Mike "MrMunka" Gillingham was telling us:
Mike "MrMunka" Gillingham nous racontait que :
Ok, I'm having a terrible time doing this. Nothing is working like I
need.

I have a few text box fields to be filled out and a simple button at
the bottom of the page to click on and have the document emailed to
one email address.

The code I have dug up here is using a routing slip or something and
every time I send the form, it attaches another email address to the
TO: field. Now I have like 12 of the same address all listed each
time I send a new email using this form.

Here's the code.

Private Sub CommandButton1_Click()
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
.Subject = "New subject goes here"
.AddRecipient "(e-mail address removed)"
.Delivery = wdAllAtOnce
End With
ActiveDocument.Route
End Sub


The form can be mailed as an attachment, I'm just having a hell of a
time getting what seems to be a simple task to work properly. Thanks
in advance.

Are you creating the form from *.dot or form a *.doc?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
M

Mike MrMunka Gillingham

Another code I have which I wouldn't mind using is this:

Sub SendDocumentAsAttachment()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed)"
.Subject = "New 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"
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub

I'm just unable to figure out how to add the commandbutton to it. I've
failed so far in getting it to work with a button. Running the macro seems to
work fine though.
 
J

Jean-Guy Marcil

Mike "MrMunka" Gillingham was telling us:
Mike "MrMunka" Gillingham nous racontait que :
It's saved as a .doc, should I save it as a .dot?
Ypu should use a *.dot.

I think that once you use "Send to Email Recipient" (Routing or otherwise),
the document "remembers" the data that was last used.
I have seen weird behaviour with documents that were used more than once in
such cases.

If you use a real template (*.dot) which itself has never been sent to an
email recipient, then whatever document you create from the template will
only be sent once and you will not get this problem.

Anyway, generally speaking, it is a better practice to use real template
than to use documents that parade as templates.


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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