interogate wrd doc?

Mr Ashim

Registered User.
Local time
Today, 18:32
Joined
Mar 4, 2004
Messages
10
Is there any way of interogating text in a word doc and having this data stored in a tbl. For instance i anticipate having to use a template or document prepared by another. Certain data within the letter i would like to use to update ?Access tbl. I cannot use the origional data source the letters are prepared from. I anticipate the data or info within the word doc to be address fields, dates and descriptions of the letter content stuff like that.

Any ideas or solutions would be greatly appreciated.
 
Mr. Ashim, I have done something like this. The hardest part will be identifying the information within the document. I will suggest that you read the overview I will present and consult the help files to fill in some of the blanks. IN PARTICULAR, consult the WORD help files for the VBA portion of the Word COM interface.

In general, you open a Word document by creating an application in VBA. Associate it with Word. At this point you have Word running but no document opened yet.

Use the FindFile object to find the fully qualified file spec of the file you wish to open. (Alternatively, create an ActiveX control that uses the FileOpen dialog box. Search this forum for Pat Hartman's articles on the subject.)

Now you have a file name. You can use the .Open method of your Word app to open the file. The file you just opened becomes the ActiveDocument. (Think of this as similar to the VBA construct "Me", which refers to the form associated with the class module containing such references.)

OK, the ActiveDocument exposes several collections. This is where it gets nasty. You've probably got TOO MANY collections to choose from.

There are various ways to deal with this. You indicate that you do not control the source of your data. That is why this will be tricky.

If you have some text clues, then you could write a VBA loop that iterates through the paragraphs of the document one at a time. There is a Search method that applies to paragraphs, so you could search for the text marker that identifies the data you see. Be aware that you have a lengthy chain of collection sub-references to isolate the text of a paragraph. Something like

ActiveDocument.Paragraphs(n).Range.Text

to see the WHOLE PARAGRAPH (as a very long string morally equivalent to a memo field is potential size.) Be aware that a paragraph can be empty if you use two hard returns or a hard return & hard page combination. I believe .Paragraphs(n).Size is available, though perhaps it is more like .Paragraphs(n).Range.Text.Size - it has been a while since I played with this stuff.

From this point you can use string functions InStr, Mid, Left, and Right to identify and extract the data you need. Have a recordset open to your table so you can immediately stuff a record full of the data. (Do a .AddNew on the recordset, copy your data, and do the .Update on the new record.)

A couple of pointers: Anything you open, CLOSE IT as soon as practicable. Don't close it until you are done with it, but get rid of open structures as quickly as it makes sense to do so. Otherwise you will deplete memory or some Windows resource. That applies to recordsets, documents, and applications.

Good luck!
 

Users who are viewing this thread

Back
Top Bottom