View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Henry[_5_] Henry[_5_] is offline
external usenet poster
 
Posts: 104
Default Form Letter in Word from Select Excel data

Beau,

I didn't realise you were calling Word from Access!
I don't know much about Access so I can only give you some general VBA hints
here.

Make sure the Doc is saved in the same directory as your DB project file.

Copy and paste my code into Access VBA

Go Tools References and tick the reference to Microsoft Word (9 for Word
2000, 10 for Word XP)

Change the line
appWD.Visible = False
to
appWD.Visible = True
This is so you can see Word open and then the document open.
Change the line
appWD.ChangeFileOpenDirectory ActiveWorkbook.Path 'Word looks here
for file
to
appWD.ChangeFileOpenDirectory Application.CurrentProject..Path 'Word
looks here
for file
Comment out all the lines from
With ActiveSheet
appWD.ActiveDocument.FormFields("DollarN").Select
appWD.ActiveDocument.FormFields("DollarN").Result = .Cells(3,
1).Value

appWD.ActiveDocument.FormFields("DollarW").Select
appWD.ActiveDocument.FormFields("DollarW").Result = .Cells(3,
2).Value

appWD.ActiveDocument.FormFields("Tax").Select
appWD.ActiveDocument.FormFields("Tax").Result = .Cells(3,
3).Value

appWD.ActiveDocument.FormFields("Total").Select
appWD.ActiveDocument.FormFields("Total").Result = .Cells(3,
4).Value

appWD.ActiveDocument.FormFields("ID").Select
appWD.ActiveDocument.FormFields("ID").Result = .Cells(3,
5).Value
End With
To here ...
and then run it from Access.

Word will open and then the Doc.
Then the Doc will print out with the fields blank ('cos we've put nothing in
them!).
You'll then have to find out how to put the results of your Query into the
form fields.
My knowledge of AccessVBA runs out here.
You'll have to figure it out yourself or try one of the Access Newsgroups.
Probably, you can keep most of the commented out lines but you'll need to
change the
Result = .Cells(X,Y).Value bits to something else and the With ActiveSheet
line as well.

Sorry I can't be of more help.
Henry


"Beau" wrote in message
...

Henry.. I know this is probably the wrong website but it is worth a
try...

Is there any way to Open WORD and populate the TEMPLATE FORM with
results from a query?

I cut and pasted the exact code you wrote for excel with obvious
problems. In trying to change the code so that it refers to an "ACCESS
SESSION" is not... well.. I have no clue what I am doing.

I understand activesession in Excel and even Word for that matter.
However.. my search for the same in ACCESS is not working.

Any pointers on how I will llink the FORMS in words to the QUERY
result?

lets assume I have a simple query that pulls PRICE AND a NAME from an
INVOICE NUMBER and I am working with the fields:
INVOICE, PRICE and NAME.

I know this is probably WAY vague but I will be happy to provide any
more info.

THanks!


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/