save word doc access automation

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
 
B

Brendan Reynolds

The reason Word isn't saving the changes is that you told it not to! :)

That's what setting .Saved = True does - it tells Word to behave as though
changes have been saved, it does not actually save them.

Try oDocName.Save instead of oDocName.Saved = True.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
J

Joanne

Brendan
Thanks for the information and the explanation.

Another instance of the importance of paying close attention to
detail. Sometimes I get so bogged down in the problem that the little
details slip right past me.

Well, back at it
Thanks again for you help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top