Setting references programatically

  • Thread starter Thread starter Marc Hillman
  • Start date Start date
M

Marc Hillman

I'm running Access 97 in a mixed Word 97 & Word 2003 environment, and using
OLE automation to transfer data from Access to Word. In order for this to
work I need a reference to "Microsoft Word X.0 Object Library" where X=8
(for Word 97)or 11 (for Word 2003). I know how to set this, but I never get
the chance. I get an error saying the reference is missing before I even get
to the form Open or Load method's to set the reference. How can I :-

a. Reliably detect which version of Word is installed, and
b. Set the reference before I load/open any forms?
_______________________________________
Marc Hillman, Melbourne, Australia
web: http://users.bigpond.net.au/mhillman/
 
Hi Marc

It is nearly impossible to solve the problem the way you are seeking to. As
soon as VBA realizes that any reference is broken, it is too late to do
anything programmatically at all. The best reference I can suggest is
michka's article:
How to guarantee that references will work in your applications
at:
http://www.trigeminal.com/usenet/usenet026.asp?1033

The better approach is is use late binding. This MS article should get you
started:
Microsoft Office 2000 automation Help file is available in the Download
Center
at:
http://support.microsoft.com/default.aspx?scid=kb;en-us;260410
 
Thanks for the quick reply, but I'm still a little stuck.

I have loop'ed through the References and detected that "Word" was not
loaded. Loaded it and all is fine.

Then I read Hint 8 of the first article where it says don't do this, but go
through the registry instead. How do I do that? What key am I looking for?
What VB functions allow Registry access?

I'm also having trouble with the Dir function. I want to locate MSWORD.OLB
so I can load it, but it's location varies according to Word version. Code
like strFilename = Dir ("C:\Program Files\Microsoft
Office\Office*\MSWORD.OLB") doesn't work. What's the trick?
 
I would use late binding, but I don't know what it is. The Office Automation
2000 help file isn't much help.

You've been very helpful already, but can I stretch the friendship and ask
for a code fragment to detect an absent or missing reference to Word?
 
Ah, I am actually using late binding, but I didn't realise it.

The problem is that I wish to call Word, and wait till the user finishes. To
do this I have declared "Public WithEvents objWord as "Word.Application",
and respond to the Quit event. The "Word.Application" bit is the problem.
Public WithEvents objWord as Object isn't legal, so how do I do late binding
with a WithEvents?
 
The article I pointed you to is the best example I can give.

Perhaps others can help.
 
Back
Top