Help with populating a word document?

C

Connor T

Hi,

I followed this guide on msdn:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dno2k3ta/html/odc_VBNETcallsVBA.asp

And have suceeded in launching word, and displaying data from my database.

However what I can't figure out is how to setup a data source in word, and
insert fields into my pre-written form from the database. I'm pretty sure
this is easily done - In fact i've seen it done in the past, but I dont know
the technical details of it. At the moment all that happens is that the
data gets appended to the end of the document!

So any ideas?

Rgds,
Dan
 
H

Helen Trim

I have an application that puts data into a Word
document. It uses Word documents that have fixed terms in
that get replaced by data.

For example, ¬Date¬ gets replaced by today's date,
¬Surname¬ gets replaced by the patient's surname.

The code is fairly simple then:

Dim Word As New WordCreateLetterClass
Word.WordApp.Documents.Open(FileName:=gstrTemplate,
ReadOnly:=True)
Word.WordApp.Application.ActiveDocument.SaveAs(strFileName)

' Do a find and replace
Word.WordApp.ActiveDocument.Range.Find.Execute
(findText:="¬SURNAME¬", replacewith:=gstrSurname,
Replace:=2)


You could use Mail Merge but the documents are very fiddly
to work with, which was why we came up with this solution.

HTH
Helen
 
C

Connor T

That sounds interesting - I shall give it a try!

I Did get a version working via mailmerge but Im not sure how portable it is
and I dont seem to be able to control the SQL which is created in order to
define the dataset.



I have an application that puts data into a Word
document. It uses Word documents that have fixed terms in
that get replaced by data.

For example, ¬Date¬ gets replaced by today's date,
¬Surname¬ gets replaced by the patient's surname.

The code is fairly simple then:

Dim Word As New WordCreateLetterClass
Word.WordApp.Documents.Open(FileName:=gstrTemplate,
ReadOnly:=True)
Word.WordApp.Application.ActiveDocument.SaveAs(strFileName)

' Do a find and replace
Word.WordApp.ActiveDocument.Range.Find.Execute
(findText:="¬SURNAME¬", replacewith:=gstrSurname,
Replace:=2)


You could use Mail Merge but the documents are very fiddly
to work with, which was why we came up with this solution.

HTH
Helen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top