Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to insert from a table into a Word 2003 document and email them using Microsoft outlook 2003 4

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi everyone,
I want to accomplish something here but actually i don't know how, i am wondering if i can get help from you.
Well i am still running Microsoft word 2003, Ms Outlook 2003 and VFP 5.0 to create prg, pjx, exe etc.... by the way i also i have VFP 6.0 but it is not installed, but if it is necessary i can install it, depends if you suggest me to do it.
This is what i want to to accomplish:
1- i have a word document that i need to email to a bunch of vendors but in that document i need to insert in a particular location of the document the Vendor name, then email this document to each of these vendor
the document is the same but in that particular location of the document their vendor name has to be inserted and then emailed it using Microsoft outlook 2003 that is setup with a POP3 and SMTP.
2- I have created in vfp 5.0 a table with all vendors name and their respective email.

can any one help me out here with some codes on how to call that word document, insert the vendor name in that particular location of the document and then be able to email it ?

Thanks in advance
 
1 - I don't know, what this refers to. Maybe you put in something else but a bookmark. A field expression for example. Analyzing the Word docs in your tempw folder should also already show this problem, I doubt it just start because you attach the file or watch it in Outlook.

2 - Yes, this is a known security feature of outlook, to prevent spam software to use outlook. Most probably a spammer kinwos better anyway and knows SMTP/POP3 or IMAP protocols in and out and has all this internally, but who knows.

There should be a part of the dialog allowing you to set a timespan, so this dialog doesn't come for the next 10 minutes or so. Another solution is to disble this in Outlook: Outlook Options has a security center, in which there are options and one of them enables you to disable the warning.

I have this setting to only warn about suspicious (automation) activity, if my antivirus program is inactive or virus definitions are outdated. This way, this security message doesn't hit me.

3 - Yes, you should always reopen the c:\tempw\Letworldole.doc inside the loop body, so you restart with no vendor name at the bookmark, otherwise each document you generate would have one more vendor name and your last generated document would have all vendor names inside the document, in each loop cycle, you would add one vendor name to the next. You always want to start with your template, so you always load it.

Bye, Olaf.
 
Ernesto,

To answer your second question: this is a standard security feature of Outlook, which you cannot turn off (as far as I know). There are a couple of workarounds:

1. Use something called Outlook Redemption (details here).

2. Use ClickYes Express, which is a free utility designed to solve this problem.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Pardon me, I am at Outlook 2010.

That means you may not find what I said about the Security Center in Outlook 2003 in exactly the same way. But I'm sure the message you see has that timeout option, also in Outlook 2003.

If all else fails you can of course take Mike's advice and use Redemption or ClickYes. If I were you I would prefer ClickYes, because redemption means to have a code change, even though just a slight one. You create a Redemption.SafeMailItem instead of letting Outlook create a mail item for you.

Bye, Olaf.
 
And if you go WAY back up in this LONG post, you will see my 21 Jan 13 15:07 reply where I advise you about using Redemption to get around the Outlook SP-2 Security Patch.

In retrospect this posting should have been put into 2 separate questions since they are very separate questions.
1. How to Automate Word
2. How to send files (e.g. Word Documents) out via Outlook as Attachments.


Good Luck
JRB-Bldr
 
Hi Everyone,
I will get back to you after i test everything again, in the mean while i really want to thanks all of you for trying to help out a guy who should know all of these by now, i really feel very embarrassed by asking some many questions and also for my bad english, anyhow thanks a lot, i will get back.
Ernesto
 
Ernesto, there is really no need to feel embarrassed. We all were beginners in VFP once, so we know what it's like to be starting out. Please don't hesitate to come back when you've got some more questions.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Hi everyone,
I am trying to run the program using oWordObj = CreateObject('Word.Application') but i am getting this error "Ole error code 0x800706ba:the RPC SERVER is unavailable" when the program reach this line

"oWordObj.Bookmarks("company").InsertAfter(vendinfo2.Company)", this line never execute, and get the error i mentioned above, here is the code i have

Note: is there anything missing here or wrong ? , the Bookmark in the word document is the same as the one when i run the program under ("Word.Basic") code, and everything is running fine, i just want to follow as you all indicated that is better to use

oWordObj = CreateObject('Word.Application') instead of oWordObj = CreateObject("Word.Basic")

Code:
PUBLIC oWordObj 
oWordObj = CreateObject('Word.Application')
USE VENDINFO
DO WHILE NOT EOF()   
   oWordObj.Documents.Open("c:\tempw\Letworldole.doc")
   oWordObj.Bookmarks("company").InsertAfter(vendinfo.Company)
   oWordObj.ActiveDocument.SaveAs("c:\tempw\"+alltrim(vendinfo.company)+".doc")
   oWordObj.Activedocument.Close() 
   SKIP 1
ENDDO
oWordObj.Quit()
oWordObj = .NULL.

* now mail them
PUBLIC oOutlookObj, oMailObj
oOutlookObj = CreateObject("Outlook.Application")

GO TOP
DO WHILE NOT EOF()
   oMailObj = oOutlookObj.CreateItem(0)
   oMailObj.To = alltrim(vendinfo.email) &&"you@somewhere.com" && after testing with your own mail address put in oMailObj.To = alltrim(Vendinfo.email)
   oMailObj.Subject = "testmail"
   oMailObj.Body = "Hi, this is a test mail"
   oMailObj.Attachments.Add("c:\tempw\"+alltrim(vendinfo.company)+".doc")
   oMailObj.Send() 
   oMailObj = .NULL.
   SKIP 1
ENDDO
use  && to close the table
oOutlookObj.Quit()
oOutlookObj = .NULL.

Any suggestion is very appreciated Thanks again
Ernesto
 
Hi Sorry i made a mistake instead of
Hi everyone,
I am trying to run the program using oWordObj = CreateObject('Word.Application') but i am getting this error "Ole error code 0x800706ba:the RPC SERVER is unavailable" when the program reach this line
"oWordObj.Bookmarks("company").InsertAfter(vendinfo2.Company)", this line never execute, and get the error i mentioned above.

instead of oWordObj.Bookmarks("company").InsertAfter(vendinfo2.Company)
should be oWordObj.Bookmarks("company").InsertAfter(vendinfo.Company)
 
What version of Word are you using?

While I was pointing out you find more infos and reference on Word.Application, you solved the problem of finding out how to SaveAs using Word.Basic, so you may as well stay there.

I and others also did state "never change a running system" several times.

The error "RPC SERVER is unavailable" juist means either Word is not installed correctly for automation, or busy. The latter is more probable, of course. So you may need to put in a DOEVENTS FORCE after Documents.Open to let Windows and Word time to open the document, before you address the bookmark in it.

Especially in a loop this can turn out to be a problem after some time and after RAM usage goes up and the system slows down. DOEVENTS FORCE forces Windows to process some events of both your application and also any other process, also freeing memory or laoding files or closing files. Not doing DOEVENTS often causes foxpro to stress the system by not giving it any chance to process other tasks than your app, espeically when executing in a loop.

Bye, Olaf.

 
The Word version you're using would still be of interest. It may also be a version issue. Maybe Word.Basic automation is what you found in Tamar's book and maybe that's more relevant with an older Word version. Maybe also a sign to upgrade your software. For example the last time I saw RPC Server errors was with Word XP. Maybe also my way to work with automation changed it to the better or the newe OS was a more stable foundation. Indeed Windows has gotten much more stable since NT times.

Bye, Olaf.
 
Olaf,
I am running Ms word 2003 professional edition with sp3, OS=WIN xp prof 32 bit sp3 and visual foxpro 5.0, this is the computer where i am working at, of course i am doing this for one of my users wich is running MS WORD 2003 STANDARD EDITON SP3, Win xp prof 32 bit too, i will a create a form, with some commands button, then create a project and then the exe file, the " ClickYes Express" that JRB-Bldr, Tamar and Mike suggested me work perfect for the security problem with microsoft outlook, the code you gave me for the mail "with do while" is working perfect too, i just tested with four records, i think the table will have about 47 records, the problem that i see that maybe could happened is if one email account is wrong or was misstyped and resides in the table, at the time of trying to email it, then it won't reach the recipient then i guess the program will fail, and will not continue to the next record i guess unless a window popup and the user select ignore from a cancel, ignore or quit from the program, that is why i told that user to acquire those email accounts by receiving those email and copy and paste them into my table, that will be the safest way.
Thanks
Ernesto
 
If you specify a wrong mail adress in outlook, the mail will still be sent and just not arrive anywhere. This won't make your code stop. A totally wrong adress, eg without an @ in it, could perhaps make outlook stop with an error popup message. You can try that. Waht would cause more dangerous problems is setting character properties to NULL or other wrong types, and of course getting low on RAM or hard drive problems or other problems during automation causeing a halt.

As you depend on the health of the system you will need to moitor it, this is never maintainance free, but it would also not be, if you weren't automating word and outlook but something else. In the end this should work sufficient and if it's to be done weekly or so you'd set it up as scheduled task and will monitor the result code logged to see, if it worked or failed. Something along that line.

Bye, Olaf.


 
You r right, what i meant was if the email i was trying to to send To was misspealed it will never reach its destination, the only way to know is go back to M outlook and check the inbox for a return email telling you that that email never was reached, so then we will need to fix that email and then later send it just from Outlook
Ernesto
 
Yes, that's true, you can't find that out right away, you will have to look into the inbox for messages of failed mails. This can also happen, if a mail adress is technically valid, but the account was dropped or changed. You can't predict that, that's something you have to live with. The only way even web applications check a mail address for validity is to send a mail. There are slightly better ways low level in "asking" the destination mail server, but sending a mail is obviously telling you sooner or later, if a mail address is valid or not.

Bye, Olaf.
 
If you use a BAD email, typically Outlook will throw an Error message (an OLE error) and the email will not go-out-the-door.

Assuming that your email address is properly formatted, within the Outlook object you can optionally add 2 flags to the outbound email itself.
Code:
oMail = oOutlook.CreateItem(0)
oMail.ReadReceiptRequested = .T.
oMail.OriginatorDeliveryReportRequested = .T.

Neither of those will GUARANTEE that the email went to the correct recipient, but if the recipient Receives the email a return email will be sent back to the sender and/or if they Read the email a return email will be sent back to the sender - this will work only if the recipient's email client has not been configured to NOT do this.

And if the email was Received and/or Read by the wrong individual, that too will not be identified.

Good Luck,
JRB-Bldr

 
If you use a BAD email said:
No, how will you ever be able to send a mail to some recipient for the first time? This is nonsense.

Because it's you and to not have any doubt, I tried it.
The only things happening if you specify oMail.To = "blah" is, Outlook prompts with proposed alternative recipients frfom the adressbook. Similar things happen, if you don't set the subject, Outlook will promt with the question, if you wish to send anyway. But if you spcify Body, Subject and To is an adress in a valid form, Outlook simply sends and doesn't directly come back to you, you can send to "blah@thissitereallydoesntexistabc.com" or whatever. Outlook doesn't check this, this will come back, but outlook doesn't check existance of mailadresses or even just servers. All outlook does is send a mail to your mail server and this must be valid, otherwise sending mail fails overall. The validity of the destnation adress only reveals itself from there, so this is found out in steps after outlook has done it's job to sned your mail to your provider. Mail is like real "snail" mail not verifying the validity of an address, until the mail is at the first post office and that tries to find where to forward the mail.

Bye, Olaf.
 
No, how will you ever be able to send a mail to some recipient for the first time? This is nonsense.

I think what JRB is saying is that Outlook will reject a mailing if the recipient address is badly formatted - not if it's an invalid email address. In other words, if it's syntactically incorrect.

That's certainly my experience. In fact, if the mail has many recipients, it only takes one badly formatted address to cause Outlook to reject the entire message.

Of course, you're right, Olaf, that Outlook has no way of knowing if the recipient's address is a genuine email address.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
if the recipient Receives the email a return email will be sent back to the sender and/or if they Read the email a return email will be sent back to the sender - this will work only if the recipient's email client has not been configured to NOT do this.

I'm glad you added that last caveat. I've had that setting turned off for years because spammers seeking to verify valid email addresses request return receipts. Using that feature to verify an email address makes your email look exactly the same as spam. You'll run afoul of more spam filters, etc.

Outlook Express used to default to sending read receipts automatically but IIRC Outlook locked it down around the time of XP SP2.
 
I think what JRB is saying is that Outlook will reject a mailing if the recipient address is badly formatted - not if it's an invalid email address. In other words, if it's syntactically incorrect.

Mike is correct.

When my client's data entry people forget to put the '.COM' or '@' into a customer's email address field or they make some other typo error that results in the email address having an invalid Format (i.e. a BAD email address - not a non-existent or wrong address) - Outlook will complain and throw an error message.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top