Hi
I use the following code to create a Word document from Access.
"job" and "auditor" are bookmarks saved in the body of the Word template. This works fine.
However, I have another Word document I want to create which has a table in the page header. I want to insert the [AuditorName] and [Job] as above into this table. I have created bookmarks in the table but as it is in the page header ".Selection.Goto Name" will not work, as it can't find the bookmark.
I tried various things e.g.
but all I get is "Run-time error 5678. Word cannot find the requested bookmark."
I then recorded the procedure as a macro in Word:
I tried inserting the relevant parts of this in the Access module but got the same error. (Incidently, running the above macro in the word document also results in a bookmark not found error.)
Any advice would be greatly appreciated.
AL
I use the following code to create a Word document from Access.
Code:
Set objword = New Word.Application
With objword
.Visible = True
.Documents.Add Template:=("i:\ia manual\templates\quality assurance review.dot")
.Selection.Goto Name:=("job")
.Selection.TypeText Text:=(Forms![frm recs tracked jobs]![Job])
.Selection.Goto Name:=("auditor")
.Selection.TypeText Text:=(Forms![frm recs tracked jobs]![AuditorName])
.ActiveDocument.SaveAs (QARname)
.Quit
End With
"job" and "auditor" are bookmarks saved in the body of the Word template. This works fine.
However, I have another Word document I want to create which has a table in the page header. I want to insert the [AuditorName] and [Job] as above into this table. I have created bookmarks in the table but as it is in the page header ".Selection.Goto Name" will not work, as it can't find the bookmark.
I tried various things e.g.
Code:
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.TypeText Text:=(Forms![frm recs tracked jobs]![Job])
.Selection.Goto Name:=("Job")
but all I get is "Run-time error 5678. Word cannot find the requested bookmark."
I then recorded the procedure as a macro in Word:
Code:
Sub Macro2()
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.GoTo What:=wdGoToBookmark, Name:="Dept"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.TypeText Text:="gg"
End Sub
I tried inserting the relevant parts of this in the Access module but got the same error. (Incidently, running the above macro in the word document also results in a bookmark not found error.)
Any advice would be greatly appreciated.
AL