Access & MS Word

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Is it possible to use access data in a certain field to
print a word document of the same name? I use access to
maintain a database of all products and have separate (or
individual) word documents explaining each product.

Example:
Access Data 01-2001
Word Document 01-2001.doc

I'm hoping I can automatically print the word doc after
running a query for a specific product.

Any ideas? Possible or wishful thinking?

Thanks in advance.
 
Sure. No problem.

Here's some code that should do it, assuming the "certain field" is named
ProductID and the documents are in the directory E:\

Dim MyFileName as String

MyFileName = "e:\" & ProductID & ".doc"

Dim mobjWordApp As Word.Application
Dim mobjWordDoc As Word.Document

Set mobjWordApp = New Word.Application
mobjWordApp.Visible = False
mobjWordApp.WindowState = wdWindowStateMaximize
Set mobjWordDoc = mobjWordApp.Documents.Open( MyFileName )
mobjWordDoc.PrintOut
mobjWordDoc.Close
mobjWordApp.Quit
Set mobjWordDoc = Nothing
Set mobjWordApp = Nothing

I'm no expert on Word and haven't included any error checking... but I would
presume that mobjWordDoc would be Null if the .doc file weren't found.

I'm sure people in a Word programming newsgroup could answer any questions
about programming Word.

Rick
 
Thanks - will give it a try.

Thanks,
Mike


-----Original Message-----

Sure. No problem.

Here's some code that should do it, assuming the "certain field" is named
ProductID and the documents are in the directory E:\

Dim MyFileName as String

MyFileName = "e:\" & ProductID & ".doc"

Dim mobjWordApp As Word.Application
Dim mobjWordDoc As Word.Document

Set mobjWordApp = New Word.Application
mobjWordApp.Visible = False
mobjWordApp.WindowState = wdWindowStateMaximize
Set mobjWordDoc = mobjWordApp.Documents.Open( MyFileName )
mobjWordDoc.PrintOut
mobjWordDoc.Close
mobjWordApp.Quit
Set mobjWordDoc = Nothing
Set mobjWordApp = Nothing

I'm no expert on Word and haven't included any error checking... but I would
presume that mobjWordDoc would be Null if the .doc file weren't found.

I'm sure people in a Word programming newsgroup could answer any questions
about programming Word.

Rick



.
 
Back
Top