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

How insert info into Word bookmark?

Status
Not open for further replies.

upplepop

IS-IT--Management
Jun 1, 2002
173
US
How do I insert something in a text field into a MS Word bookmark. I already have code to create the word document.

I found this code somewhere, but it doesn't work:

appWord.Goto Name:="FirstName"
appWord.TypeText Text:=strFirstName


"FirstName" is the name of the Word Bookmark; I already stored the First name in strFirstName.
 
Does anyone know how to reference an existing word bookmark? I still have not found the code!
 
Hi Upplepop,

Try this.

Function PrintReportWithWord(frmDataSource As Form)

Dim objWord As Word.Application
Dim rst As Recordset
Dim strSQL As String

' Launch Word and load the report template
Set objWord = New Word.Application
objWord.Documents.Add _
Application.CurrentProject.Path & "\HSInitial.dot"'the template I am exporting too
objWord.Visible = True

With objWord.ActiveDocument.Bookmarks

'**** Repeat this line of code for as many controls\bookmarks needed

'test each line for null.
If IsNull(Forms![Add Site Details to Area Office]![Address 1]) Then 'on the result of this test
objWord.ActiveDocument.Bookmarks("areaaddress1").Range.Paragraphs(1).Range.Delete 'delete bookmark if field is null
.Item("AreaInsertPoint").Range.Text = vbCr 'add a carrage return
Else
.Item("areaaddress1").Range.Text = Forms![Add Site Details to Area Office]![Address 1] 'or fill in the bookmark
End If

End With

' We're done
Set objWord = Nothing
End Function


I hope this works for you

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top