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!

inserting fields from current record into word doc

Status
Not open for further replies.

toffa

Programmer
Aug 24, 2004
77
AU
hello im am trying to insert fields from the current record into a word document and can get it to work except when i need to insert the field 2 or more times.

here is my code.

Private Sub mergedoc_Click()
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

Exit Sub
End Sub
how do i get the field to repeat in two or more different locations on word.
 
I've not attempted to do what you're doing. But, could you use Mail Merge within word to access your table (or query)?
 
I could have done this and it works perfect but what i was trying to do was to get access to automate the whole process instead of having to find the specific record in the mailmerge whis may not be represented by the record number in access.

Anyway looks like i have sorted the problem to a degree by referencing the bookmark and then updating the feild.

I think i may go back to mailmerge and set links on the doc to open the word file.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top