[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send Word form Via email using VB

Posted on 2004-11-24
4
Medium Priority
?
358 Views
Last Modified: 2011-10-03
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)
0
Comment
Question by:BadRastaMan
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
JasonRodrigues earned 500 total points
ID: 12672081
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
 

Author Comment

by:BadRastaMan
ID: 12699419
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
 
LVL 1

Expert Comment

by:JasonRodrigues
ID: 12713125

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
 

Author Comment

by:BadRastaMan
ID: 12728075
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question