This means that your Access VBA project contains no reference to the Word
object library. Instead, you create the COM object on the fly and the
references to object properties and methods are resolved at run-time.
This means you must declare all Word object variables "As Object". So
instead of:
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
...
Set wdApp = New Word.Application
you would need to say:
Dim wdApp As Object
Dim wdDoc As Object
...
Set wdApp = CreateObject("Word.Application")
Note that CreateObject is preferable in any case because it works with both
early and late binding.
Late binding has some disadvantages, notably that you lose the intellisense
which gives you a nice list of methods and properties when you type an
object variable, and you lose the built-in constants that are defined in the
object library.
I use conditional compilation to get the best of both worlds.
At the top of your module, add a compiler constant:
#Const EarlyBinding = 1
Then, in any procedure where you use these objects, put a structure like
this:
#If EarlyBinding Then
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Debug.Assert wdDialogFilePrint = 88
Debug.Assert wdSendToNewDocument = 0
#Else
Dim wdApp As Object
Dim wdDoc As Object
Const wdDialogFilePrint = 88
Const wdSendToNewDocument = 0
#End If
In other words, when you are late binding, change the declaration of each
object to "As Object" and declare any constants you use, but when you are
early binding, declare the objects as what they really are and use
Debug.Assert to verify you have the correct value for each constant.
When you are ready to deploy your application, simple remove the reference
to the Word object library and change the constant declaration to:
#Const EarlyBinding = 0
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
hughess7 said:
Oh how I wish it was that simple!!! I have already tried to reproduce the
word template the guys use as their audit report, to cut out word
completely
to simplify matters. But it is a design nightmare and not really
practical.
The word report is several pages long consisting of sections and
paragraphs
of 'boier text' with calculations / values etc inserted from the database
in
the middle of sentences.
eg The total found was #.## which equates to an error level of #%. etc
etc
etc
Just aligning all the paragraphs of 'boiler text' is tedious but trying to
insert values in alignment is impossible! I actually read a post on this
forum asking for advice on a similar scenario to use access or word
template
and you advised on word 'hands-down'. I can get a mail merge to work but
it
produces a new document and then I need to secure it somehow so it can not
be
amended by an end user. I thought the most appropriate way to do this
would
be to have the end result produced in PDF, direct from the Access db, as I
have read there are ways round a document that is password protected - eg
save as etc.
Help!
Sue