best way to merge to word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a database and I want to pass some varables to Word to merge. The way
I have it on my machine is I have a Macro and I pass some varables to alter
the Macro.
However, to do this for everyone I would need to install the Macro on every
machine or every document.
What I was wondering is would it be ok to pass all the SQL statement from
the database to word to save setting up the Macro on every machine in the
office? Its not a big statement (just usual mail merge code) but would it
slow the opening of the document up?

Many thanks, James
 
Hi:

What you could do is put your Word Macro code as part of Access VBA code and
set a refernce to Word. This way you do not need to run a Word Macro.

You could instantiate Word like this --

Dim objWord as Word.Application 'Make a reference to "Microsoft Word Object
Library"
On error resume next
Set objWord = GetObject(,"Word.Application") 'checks for running instance of
Word
if objWord is Nothing then
Set objWord = CreateObject("Word.Application") 'if Word not running
instantiate new copy
objWord.Visible = True 'New instnace of Word must be made visible
end if
On error goto 0

With objWord
'Put your macro code here
'preface word objects in code with objWord here like
objWord.ActiveDocument
End With

Hope this helps.

Regards,

Naresh Nichani
Microsoft Access MVP
 
Hi,
Thanks for your reply.

I have done what you say below, but unless I start word first it says
"ActiveX component can't create object".

It works when I open a new document in word and then click the button but it
comes up with the error "Word could not merge the main document with the data
source because the data records were empty or no data records matched your
query options." but then it merges perfectly.

Any suggestions?
 
Back
Top