I'm working on a Word add-in that will need to save some simple
information and retrieve it later. There will be a small number of
records, probably no more than ten, and each record will have just two
bits of information: a record number and a string. That's it. This
add-in's needs are way too basic to be using extensive ADO or DAO data
controls, linking them to an Access file or whatever.
I've created pseudo databases before in regular VB 6 by using either
sequential access or random access files. I would have no trouble in
creating a pseudo-database using these technologies. However, each
PDB is for its own Word document. In other words, every PDB is
information about a specific Word document, and only that document
alone. If I used sequential access or random access files, I could
simply name the text file after its corresponding Word file. Example:
Janis.doc has a PDB file named Janis.dat. Just one problem. If the
user changes a document's name, the ActiveDocument.Name command can no
longer be used to find the PDB file. Also, there's the danger that a
user could find the PDB file and mess with it.
I'd much rather save the PDB info in the Word document itself in a way
that the user cannot see. It's going to be a very small amount of
data and therefore shouldn't add much to a file's size. I noticed in
the VBA IDE under "Normal" there's something called MyDocument. Is
this a property that every Word file has? Can I save the info in
there somehow? I did a keyword search of the vba news group's
archives for this, but didn't find anythings.
I'm used to VB 6 (and RB '06) and am still kind of getting my feet wet
with VBA. Oh, and the version I'm using is Word XP ('02). I'm
grateful for any help offered.
Jezebel - 14 May 2006 09:06 GMT
Save the information as a document variable. Simplest is usually to convert
the values to strings, then use the Join() function to pack it all into a
single value. And use the corresponding Split() function to retrieve it.
ThisDocument is not a *property* of the document. It *is* the document. Or
at least, in a programming sense, a reference *to* the document. Within the
IDE it might be useful to you as a place for code; but it's not a place to
store data. Sounds like you need to invest a bit more time in the Word IDE
and exploring the Word object model before you go much further with your
add-in.
> I'm working on a Word add-in that will need to save some simple
> information and retrieve it later. There will be a small number of
[quoted text clipped - 26 lines]
> with VBA. Oh, and the version I'm using is Word XP ('02). I'm
> grateful for any help offered.
Helmut Weber - 14 May 2006 09:07 GMT
Hi Tom,
learn abut docvariables.
That's all you need.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"