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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datafields in Word document

Status
Not open for further replies.

isonlyme

Programmer
Apr 20, 2002
171
PR
Is there a possibility to create a Word document and use this from within VFP (5.0) whereby the fields from variuos dbf's are filled in on that document when printing, faxing or e-mailing ?

thanks for any suggestions
 
Wilfredo

This runs in VFP5.0, instead of using a cursor, you can substitute your table.
Code:
LOCAL ldDate
ldDate = DTOC(DATE())
 oWord = CREATEOBJECT("word.application")
 loDocument=oWord.Documents.ADD()
 CREATE CURSOR myCursor (name c(20),address c(30))
 INSERT INTO myCursor (name,address) VALUES ("Mike","123")
GO top
  WITH oWord
            loSelection = oWord.SELECTION
            loSelection.PageSetup.TopMargin = 30
            loSelection.PageSetup.RightMargin=50
            loSelection.PageSetup.LeftMargin=50
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.PageSetup.BottomMargin = 30
            loSelection.FONT.SIZE = 12
            loSelection.FONT.NAME = "times"
            loSelection.TypeText(ALLTRIM(ldDate))
            loSelection.typeparagraph
            loSelection.typeparagraph
            loSelection.Font.Bold = .T.
            loSelection.TypeText(ALLTRIM(PROPER(myCursor.name)))
            loSelection.typeparagraph
            loSelection.FONT.SIZE = 10
            loSelection.FONT.NAME = "times"
            loSelection.Font.Bold = .F.
            loSelection.TypeText(ALLTRIM(myCursor.address))
        ENDWITH
 oWord.visible = .t.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first or check this link
 
thanks Mike, will try it and let you know.

wilfredo
 
Mike,

Works ok but is there any possibility to determine exact places on the document where the data should be filled in ?

The idea is to have a text which extracts data and fill them in as follows:

name
addres
....

our file: (dnr.dnrnr) (please repeat in all correspondance)


Antwerp, (date)

We have pleasure in informing you that, without unforeseen circumstances, following cargoes will arrive at (dnr.vesselarrivaldate) per ms (dnr.vesselname) from (dnr.portofloading):

Shipper: dnr.nameshipper
dnr.addressshipper
....

containernr seal marks goods description weight
----------- ---- ----- ----------------- ------
(scan for all containernumbers associated with dnr.dnrnr + another dbf which contains details of the goods per container)

May we kindly ask you to ... blablabla

_____________

The same goes for other (more complicated documents) where the data should be outlined at the right side of the page:

Please load at (nco.name)
(nco.address ...)

Date Time Size Type empty out ref full in ref
---- ---- ---- ---- --------- --- ------- ---(scan for ctr.dnrnr)


____________

As far as text+data is concerned it can easily be done from within the .prg but I can't figure out how to make up a Word.doc and THEN fill in the data on the correct places.

Thanks for your efforts

wilfredo

 
wilfredo

I'm not sure exactly what you mean. The suggestion above will create a blank word document:
oWord = CREATEOBJECT("word.application")
loDocument=oWord.Documents.ADD() && This creates a blank document.

And the rest is just trial and error as to where to place thing.
loSelection.PageSetup.TopMargin = 30
loSelection.PageSetup.RightMargin=50
loSelection.PageSetup.LeftMargin=50
loSelection.PageSetup.BottomMargin = 30


The above four lines, just sets up the document margins (we needed to adjust it for our own purposes).

loSelection.typeparagraph

The above line is just like using "ENTER" (it creates a blank line in the document).

loSelection.TypeText(ALLTRIM(PROPER(myCursor.name)))

The above line puts the "name" at that position (You can format it with transorm or other formating functions.

loSelection.FONT.NAME = "times"

The above line changes the font at that point in the document.

But once all the formatting is done, you can re-use the code, and just change the record in your tables. Like a mail-merge function in Word, but in reverse.

The way we use the above function, was a template (a word document saved as a template) letter we need to send to 240 clients and all we need to change was the date and customer's name and address.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks Mike but maybe I should rephrase my question:
is there any ^possibility to arraange the document into "columns" without the hasle of having to write code for every selection.pagesetup.top/left/rightbottom/margin

Furthermore the idea would be to use an EXISTING Word.doc that coukld be filled in, not create a new one everytime.

wilfredo
 
wilfredo

is there any ^possibility to arraange the document into "columns" without the hasle of having to write code for every selection.pagesetup.top/left/rightbottom/margin

Furthermore the idea would be to use an EXISTING Word.doc that coukld be filled in, not create a new one everytime.


Yes as I mentioned above, WE used a template letter, where we just loaded the template and "placed" a few pieces of information required a printed the document. So in your case you would create your template document (with columns if you need them) and open it up in VFP through automation, select all, copy it (since technically shouldn't modify the template itself) and create a new document, paste the template and fill-in the rest of the required inforamtion based on your fields.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I think I understand what you are looking for:

Standard word doc with some bookmarks such as

name, address, city st, zip etc.........(whatever)

I have a few programs, screens, and required tables I might be able to get together for you. I have not released any of the above to the general public, but maybe its time I did. Let me know if you are interested.

Bryan Holmstrom
bholmstrom@conduitsoft.com
 

Wilfredo, in Word itself, have you considered the MailMerge feature under Tools?

You can import .dbf fields directly and without conversion, into Word fields you've defined.

Al

 
I would agree with Al. If you just want to replace various parts of the document with data, that is what WORD does with a merge.

The only reason to use Word Automation is if you wish to change the document for various reasons during the process.

Now, you could also write code to use automation to do the merge from within VFP. I can't come up with the code to deal with this off the top of my head but I am sure it can be done.



Don
dond@csrinc.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top