J
Joanne
I am opening a word doc in access (office 2000, win xp), setting the
bookmark values, and then I want to save the doc with the bookmarks
values in place. Bookmarks are referenced to my access form.
Using the F8 key to rumble thru the code, the recordset is correct,
the loop to set the bookmarks is correct, and I see them plug-in when
watching the word doc while going thru the loop.
My problem is that the document won't save with the values in the
bookmarks.
Here is a bit of my code showing the routine I am using
Function SetBookmarks()
Dim oWordapp As Object
Dim oDocName As Object
Dim oRst As DAO.Recordset
Dim BsSql As String 'sql stmt to get docs with bookmarks
Dim sFilename As String
Set oWordapp = CreateObject("Word.Application")
oWordapp.Visible = True
BsSql = "SELECT tblDocumentList.DocNamePath FROM tblDocumentList" &
_ " WHERE (((tblDocumentList.Bookmarks) = True))"
Set oRst = CurrentDb.OpenRecordset(BsSql)
If Not oRst Is Nothing Then
Do While Not oRst.EOF
sFilename = "" & oRst("DocNamePath")
If Len(Dir$(sFilename)) > 0 Then
Set oDocName = oWordapp.Documents.Open(sFilename)
If Not oDocName Is Nothing Then
With oWordapp.ActiveDocument.Bookmarks
If oWordapp.ActiveDocument.Bookmarks.Exists("FName") = True Then
.Item("Fname").Range.Text = Nz(Me!FName, "")
End If
If oWordapp.ActiveDocument.Bookmarks.Exists("Midinit") = True Then
.Item("MidInit").Range.Text = Nz(Me!Midinit, "")
End If
End With
oDocName.Saved = True
DoEvents
oDocName.Close
Set oDocName = Nothing
oRst.MoveNext
End If
End If
Loop
End If
oWordapp.Quit
oRst.Close
Set oWordapp = Nothing
Set oDocName = Nothing
Set oRst = Nothing
End Function
Can you tell me where I am going wrong here please? Do I need to
reference the path and filename in the save code line? I will be
overwriting the existing file and really do not want the "Do you want
to replace blah blah?" dialog box to come up as I rumble thru 22 docs
in this loop.
Thanks for your consideration and expertise
Joanne
bookmark values, and then I want to save the doc with the bookmarks
values in place. Bookmarks are referenced to my access form.
Using the F8 key to rumble thru the code, the recordset is correct,
the loop to set the bookmarks is correct, and I see them plug-in when
watching the word doc while going thru the loop.
My problem is that the document won't save with the values in the
bookmarks.
Here is a bit of my code showing the routine I am using
Function SetBookmarks()
Dim oWordapp As Object
Dim oDocName As Object
Dim oRst As DAO.Recordset
Dim BsSql As String 'sql stmt to get docs with bookmarks
Dim sFilename As String
Set oWordapp = CreateObject("Word.Application")
oWordapp.Visible = True
BsSql = "SELECT tblDocumentList.DocNamePath FROM tblDocumentList" &
_ " WHERE (((tblDocumentList.Bookmarks) = True))"
Set oRst = CurrentDb.OpenRecordset(BsSql)
If Not oRst Is Nothing Then
Do While Not oRst.EOF
sFilename = "" & oRst("DocNamePath")
If Len(Dir$(sFilename)) > 0 Then
Set oDocName = oWordapp.Documents.Open(sFilename)
If Not oDocName Is Nothing Then
With oWordapp.ActiveDocument.Bookmarks
If oWordapp.ActiveDocument.Bookmarks.Exists("FName") = True Then
.Item("Fname").Range.Text = Nz(Me!FName, "")
End If
If oWordapp.ActiveDocument.Bookmarks.Exists("Midinit") = True Then
.Item("MidInit").Range.Text = Nz(Me!Midinit, "")
End If
End With
oDocName.Saved = True
DoEvents
oDocName.Close
Set oDocName = Nothing
oRst.MoveNext
End If
End If
Loop
End If
oWordapp.Quit
oRst.Close
Set oWordapp = Nothing
Set oDocName = Nothing
Set oRst = Nothing
End Function
Can you tell me where I am going wrong here please? Do I need to
reference the path and filename in the save code line? I will be
overwriting the existing file and really do not want the "Do you want
to replace blah blah?" dialog box to come up as I rumble thru 22 docs
in this loop.
Thanks for your consideration and expertise
Joanne