Send Word form Via email using VB

Hello All,
I use this bit of code to send an email by pressing a button on a form in
Excel...
Private Sub Button91_Click()
   'Application.Dialogs(xlDialogSendMail).Show
   ActiveWorkbook.SendMail Recipients:="**********@epcor.ca"
   MsgBox "Your meter read was sent", vbInformation, "****Meter Reads"
But When I try to use the same code in a Word document...
Private Sub Button91_Click()

   ActiveDocument.SendMail Recipients:="************@epcor.ca"
   MsgBox "Your meter read was sent", vbInformation, "*****Meter Reads"
 End Sub

I get an error msg. "Wrong number of arguments or invalid property
assignment (Error 450)"

Can you please let me know how to send an active MS Word form when a button (button is on the form) is pressed & have that form sent to the same email address every time.
As per the info above I figured out how to do it with Excel but I cannot get it done in Word

Thnx,
Sheldon
(BadRasta)
BadRastaManAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JasonRodriguesCommented:
Hi Sheldon,

There is no way of specifying the e-mail address manually which I can think of in word. The best option would be be create a mail merge for this document with the e-mail address specified in a specific field say 'email' and then you could do it as below

With ActiveDocument.MailMerge
    .Destination = wdSendToEmail
    .MailAsAttachment = False
    .MailAddressFieldName = "email"   ' Field name in the data source where the email address is stored
    .MailSubject = "*****Meter Reads"  'You could put a different subject to it
    With .DataSource   'In case you want any specific record to be sent or do not include this with statement
       .FirstRecord = 1
       .LastRecord = 1
    End With
    .Execute Pause:=False 'Set pause to true if you want it to be displayed.
End With
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BadRastaManAuthor Commented:
Hi Jason,
Thanks for the suggestion, I seem to have a problem with this code "being the rookie that I am" when I cut & paste the code you suggest
(between, Private Sub CommandButton1_Click() & End Sub) my button does not work
Can you please let me know how to have this work with my submit button
By the way I’m running office 2003 on Win XP Pro

Thanks,
Sheldon
0
JasonRodriguesCommented:

Are you getting any error or nothing happens when you click the button. If the case is the latter then you will have to assign the macro to the button. If you are getting an error do let me know the error
0
BadRastaManAuthor Commented:
Hi Jason,
Sorry for being such a pain, I will go through what I am doing step by step hopefully you can see where I am making my mistake...
I'm Running MS Word 2003 & VB 6.3 on WinXP Pro
In Word I chose... View | Toolbar | VB select Design Mode
Click on the Command button
Double click on the button itself to enter into the VB Editor
In The Editor window...
Private Sub CommandButton2_Click()

End Sub
... Is displayed
I copy & paste your code in it as so...
Private Sub CommandButton2_Click()
With ActiveDocument.MailMerge
    .Destination = wdSendToEmail
    .MailAsAttachment = False
    .MailAddressFieldName = "s.pottinger@shaw.ca"
    .MailSubject = "*****Meter Reads"
    With .DataSource  
       .FirstRecord = 1
       .LastRecord = 1
    End With
    .Execute Pause:=False 'Set pause to true if you want it to be displayed.
End With
End Sub

1. Where I have my email address should I be defining a specific location on the document where the email address resides// an example would be, a specific place like in excel, cell A2
2. I'm not sure what to do with the "With .DataSource"

...Then I press save, when I go back to my document (form) and press the button I get debug dialog box...
"runtime error '5852'" "requested object is not available"
I press debug & get "  .Destination = wdSendToEmail" highlited

I hope this was not too long & boring for you, us newbies tend to do that

Thnx,
Sheldon


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.