Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access word mail merge question

Status
Not open for further replies.

neerajam

Technical User
Mar 4, 2002
23
0
0
US
I have a list of 14 soccer players that get the same information on a regular basis. I set up an access database with their personal information. I also set up a standard word document with lastname and firstname, address, city, and state bookmarks. I have no problem with doing it for a single player. However, I am having a problem when preparing the same document for all. The way I had it in my mind was select a record, get the last and first names and place them at their bookmarks, print it out and then do the same for the next 13 records. However, it is not. Any suggestions why. Thanks in advance.


Dim objword As Word.Application
Dim db As Database
Dim rsdata As DAO.Recordset

Set db = CurrentDb
Set rsdata = db.OpenRecordset("SELECT lastname from tblplayers")
Set objword = New Word.Application
objword.Visible = True

objword.Documents.Open ("mailmerge.doc")
Do While Not rsdata.EOF
objword.Selection.GoTo what:=wdGoToBookmark, _ name:="lastname"
objword.Selection.TypeText rsdata("lastname")
objword.Selection.GoTo what:=wdGoToBookmark, _ Name:="firstname"
objword.Selection.TypeText rsdata("firstname")
objword.ActiveDocument.PrintOut
rsdata.MoveNext
Loop
Set objword = Nothing
 
Replace this:
objword.Selection.GoTo what:=wdGoToBookmark, _ name:="lastname"
objword.Selection.TypeText rsdata("lastname")
objword.Selection.GoTo what:=wdGoToBookmark, _ Name:="firstname"
objword.Selection.TypeText rsdata("firstname")
objword.ActiveDocument.PrintOut
By something like this:
With objword
.ActiveDocument.Bookmarks("lastname").Select
.Selection.Text = rsdata("lastname")
.ActiveDocument.Bookmarks.Add Name:="lastname", Range:=.Selection.Range
.ActiveDocument.Bookmarks("firstname").Select
.Selection.Text = rsdata("firstname")
.ActiveDocument.Bookmarks.Add Name:="firstname", Range:=.Selection.Range
.ActiveDocument.PrintOut
End With

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top