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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with bookmarks ms word

Status
Not open for further replies.

toffa

Programmer
Aug 24, 2004
77
AU
Hi
i am using access to open word and place feilds into a document. the problem i am having is i need to use the fields several times.
At the present the fields are going across as bookmarks, when i try to ref the bookmark in word i only get the bookmark name and not the text inside the bookmark. Is there an alterate way of doing this.

Chris
 
ActiveDocumet.Bookmaks("bookmarkmamr").Rang.Text

Gerry
 
This is the code i have so far
i dont undersatnd where i would put your code into this.


On Error GoTo MergeButton_Err

Dim objWord As Word.Application


Set objWord = CreateObject("Word.Application")

With objWord
.Visible = True


.Documents.Open ("C:\Circs\accessdocs\Request for Docs.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("bus").Select
.Selection.Text = (CStr(Forms!jobs3!bus))
.ActiveDocument.Bookmarks.Add Name:="bus", Range:=Selection.Range
.ActiveDocument.Bookmarks("buscon").Select
.Selection.Text = (CStr(Forms!jobs3!buscon))
.ActiveDocument.Bookmarks.Add Name:="buscon", Range:=Selection.Range
.ActiveDocument.Bookmarks("busfax").Select
.Selection.Text = (CStr(Forms!jobs3!busfax))
.ActiveDocument.Bookmarks.Add Name:="busfax", Range:=Selection.Range
.ActiveDocument.Bookmarks("busphone").Select
.Selection.Text = (CStr(Forms!jobs3!busphone))
.ActiveDocument.Bookmarks.Add Name:="busphone", Range:=Selection.Range
.ActiveDocument.Bookmarks("busemail").Select
.Selection.Text = (CStr(Forms!jobs3!busemail))
.ActiveDocument.Bookmarks.Add Name:="busemail", Range:=Selection.Range
.ActiveDocument.Bookmarks("cl").Select
.Selection.Text = (CStr(Forms!jobs3!cl))
.ActiveDocument.Bookmarks.Add Name:="cl", Range:=Selection.Range
.ActiveDocument.Bookmarks("clnumb").Select
.Selection.Text = (CStr(Forms!jobs3!clnumb))
.ActiveDocument.Bookmarks.Add Name:="clnumb", Range:=Selection.Range
.ActiveDocument.Bookmarks("dofinj").Select
.Selection.Text = (CStr(Forms!jobs3!dofinj))
.ActiveDocument.Bookmarks.Add Name:="dofinj", Range:=Selection.Range
.ActiveDocument.Bookmarks("inscon").Select
.Selection.Text = (CStr(Forms!jobs3!inscon))
.ActiveDocument.Bookmarks.Add Name:="inscon", Range:=Selection.Range
.ActiveDocument.Bookmarks("inscomp").Select
.Selection.Text = (CStr(Forms!jobs3!inscomp))
.ActiveDocument.Bookmarks.Add Name:="inscomp", Range:=Selection.Range

End With


MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
MsgBox Err.Description
objWord.Selection.Text = ""
Resume Next
Else
MsgBox Err.Description
End If
 
Perhaps you could try something based on:

Set oRange = ActiveDocument.Bookmarks(bus).Range
oRange.Text = (CStr(Forms!jobs3!bus))
ActiveDocuments.Bookmarks.Add sBookmark, oRange

The last line re-sets the bookmark to span the inserted text, so that it can be updated with new values next time through. You may not need this if you're only processing one set of records at a time.

note too that there is no selecting going on, so the code will run much faster than with your version.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top