How do I create a button to reset a form document?

  • Thread starter Mike MrMunka Gillingham
  • Start date
M

Mike MrMunka Gillingham

Hello!
I've created a form document that will be used to fill out some text fields
and then emailed. I think I've figureed out how to make the command button
send the document as an attachment. My next task is to create a second button
to reset all the fields to blank so it can be used again with out re-opening
the document. Any ideas on how to do this?

I also thought of another question...
Whats the code to add text to the message body of the email?
Example: "This email containes an attachment for a new client."

Thanks in advance.
Mike
 
D

Doug Robbins - Word MVP

I assume that you are using formfields in a document that is protected for
forms. If that is the case, you would have the button run a macro that set
the .Result property of each formfield to "".

To add text to the body of an email message, you will need to use the
Outlook Object Model.

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

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


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

"Mike "MrMunka" Gillingham"
 
M

Mike MrMunka Gillingham

How do I add the subject and recipients to this code? I've tried a few things
like .Subject = "subject here" but I'm unable to get anything I try to work.

Private Sub CommandButton2_Click()
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub

Thanks in advance.

Mike
 
D

Doug Robbins - Word MVP

Did you look at the link that I suggested?

If you had, you would have found the following code:

Sub SendDocumentInMail()

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

On Error Resume Next

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

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

With oItem
'Set the recipient for the new email
.To = "(e-mail address removed)"
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Set the subject
.Subject = "New subject"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub


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

"Mike "MrMunka" Gillingham"
 

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