Word Merge .. again ... I think???? (1 Viewer)

phil_s

New member
Local time
Today, 17:55
Joined
Mar 12, 2008
Messages
7
Hi all,

have a query here as being new to Access and VBA it's leaving me dumbfonded.

I have (well actually my boss) has the need to export data from Access to a MS Word document in a formatted manner. OK, so I have started to go down the line of a Word template with unique characters inside it to identify the fields I want replaced (e.g. "<<unique-id>>") and then to use the VBA replace commands to replace the "<<unique-id>>" with the actual value.

OK, so looking through the threads I have been able to start up word, and even replace a single instance of the characetrs to replace, but when I come to loop around obviouly the characetrs I am looking for to replace are now gone!!! So I am obviosuly missing something basic in my understanding , so I wonder if anybody can point me to a good example or some text that explains how to do it.

To give a bit more context, imagine a word.dot template as follows:

--------------------------------------------------------

<< unique-id>> <<title>> <<date>>
--------------------------------------------------------

I want my outcome when I loop throught the records to look something like:
--------------------------------------------------------
000001 A title 01/01/2001
000002 B title 01/02/2002
000003 C titile 01/01/2008
--------------------------------------------------------

You get the idea?

as I said I am really new at this and any help woudl be appretiated.

Oh please note, I am using Access 2000 and Word 2000 (dont know if that matters?).

Your help would be appretiated
 

GaryPanic

Smoke me a Kipper,Skipper
Local time
Today, 09:55
Joined
Nov 8, 2005
Messages
3,294
ok- have a look at the "super easy word" function

this in essense in a word merge on either 1 record or a whole table .

it good because it uses all word functionality
 

phil_s

New member
Local time
Today, 17:55
Joined
Mar 12, 2008
Messages
7
Gary, thanks for the response but this does not really do what I wanted.... what this does is export data to set fields in a word document....

What I am trying to do is to use a word.dot template and then use the mergefield function and to export the record data from access, but driving the whole process from Access.

I have this mornign been trying to pick appart some vba I found that does a similar job, but I do not have it here to ask the questions I have using the correct vba terminology, but I can explain what I have found.

So the VBA does the following:
1) instantiates a word instance,
2) then opens the *.dot template and appends it to the documents object,
3) it then sets the headers/footers and generic formatting information,
4) then it passes to the .ActivateMerge (think this was the function) the name of the database and the query to run.

I presume that Word receives these parameters, uses the db name as the data source and then runs the query, to carry out a sort of controlled mail merge.... I can conceptually get this in my head.

Howevere, what I cannot understan is how the query works, again conceptually I can understand that Word applies the query to the data source to retrieve its data, and I have been looking in the example database I have and word templte, but I am not able to fnd the query anwhere..... do you have any idea where the query may be stored or how I get to it.... or am I just rambling!!!!!!

I will try to update this pos over the weekend, but I have to extract and find all the code on the laptop again......

I'm getting there and I think what I have seen is exactly what I want, I just have to work out where the query is stored and then I can "cobble" something together.. hey perhaps I could post my exceptional code (bad that is) as an example as I dont seem to have found a good example here.... but then I gotta crack it first.....

Anybody please feel free to respond and leave any thoughts that may help......

Gary thanks for the info so far.
 

SikSlk

Registered User.
Local time
Tomorrow, 02:55
Joined
Aug 30, 2006
Messages
39
Actually having a bit of trouble on the same thing at the moment.... Trying to add multiple records to a particular section on a word document.

I initially did a string which was made up of the connected fields of a record together, looped it, then added the final string to the word document.

Worked fine till I hit the 255 character limit, now im here and still looking.

Sorry I cant be of help, but if 255 characters can get you out of trouble then it could get you going.
 
M

Mike375

Guest
Phil,

Since I might be missing what you want I will be brief. If I am on target I will elaborate.

In a Word.doc you put Bookmarks and Access will open the Word.doc and insert the required data. If letterhead is need then that is also done into the footer/header.

If you want the results of a query to go in that is done in the template. On the query name in the data base window, right click and then click copy. Open Word.doc and then select Paste Special. This will link the query and Word. You open the Word.doc and then postion and format how the query will look. When code opend the Word.doc there will be no boxes adsking to confirm etc. If the query data changes that is reflected when the the Word.doc is opened.

The linked query will push writing that is below it....up and down according to the number of records the query has. You can format it so it looks like you typed the data into Word.

As I said at the start I might be on a different page to you. If I am on the same page I will elaborate
 

SikSlk

Registered User.
Local time
Tomorrow, 02:55
Joined
Aug 30, 2006
Messages
39
Finally tracked down my post... as above i figured instead of a form field it needed to be a bookmark.

Used the following:

doc.Bookmarks("bookmarkname").Range.Text = Forms![formname]![txtbox]

(so simple now... but this has been my days work... im going home)
 

Users who are viewing this thread

Top Bottom