473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with populating a word document?

Hi,

I followed this guide on msdn:

http://msdn.microsoft.com/library/de...ETcallsVBA.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
Nov 21 '05 #1
2 996

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(str FileName)

' 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
Nov 21 '05 #2
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.
"Helen Trim" <he********@REMOVEporthosp.nhs.uk> wrote in message
news:05****************************@phx.gbl...

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(str FileName)

' 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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: rainbowii7 | last post by:
Calling all programmers for helllllllllllllllppppp!!! i am currently doing a uni degree and our lecturers have set us the task of making a game in JavaScript. i chose to do a hangman game and...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
0
by: Linda Cacina | last post by:
Hello all you fine folks, Here is some code I am using to merge data from a single record Access 2K3 table into a NEW word document based on a pre-defined Word merge template doc. All I want to...
10
by: Elizabeth Harmon | last post by:
Hi All I am attempting to open a Word App from a web page on the client and so far everything works (After reconfig of dcomcnfg for Microsoft Word Document). I have one minor problem, i cannot...
6
by: SteveM | last post by:
Hi, I am needing some help/advice on how to display a word document in my ASP.NET web pages that can update itself from a word document located on the server. The idea here is that when the user...
8
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields...
2
by: theronnightstar | last post by:
I am writing an anagram program for my fiance. Figured it would be an excellent task to learn from. The way it is supposed to work is it reads in a word list from a file into a temporary...
6
by: cj2 | last post by:
I need to create a cover letter in VB. It will have a customers account number at the top and be addressed to them by name for example (Dear Mr. Smith). After this it will be the same text for...
3
by: Auslander | last post by:
I'm new to VBA, and trying to learn how to write some code to open a word template from access and populate it using Document Properties. Here's my code: Private Sub OpenWindows_Click() Dim...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.