auto filling bookmarks in word2000

J

Joanne

I am trying to automate the filling in of bookmarks in a word document
with information in my access table.
This is the coding I am using, but something is wrong with it. What
happens is I get a dialog box telling me I can only open in read only
mode as the file is "in use by another user".
SInce it opens only in 'read only' mode, my bookmarks are not filled
in and I am not sure if that portion of the function is working
either.

Could someone help me find the error of my ways please?
I am using MSOffice 2000 on a winxp machine.

Function SetBookmark()
Dim oWrd As Word.Application
Dim oDoc As Object

' Start Microsoft Word and open the document.
Set oWrd = CreateObject("Word.Application")
oWrd.Documents.Open "C:\NMWorkPackage\DirectDepAuthorization.doc"

'Pass the field info to the word bookmark
With oWrd.ActiveDocument.Bookmarks
.Item("SSN").Range.Text = frmEmpContInfo.SSN
End With

'Printout the doc with the bookmarks in place
If Not oDoc Is Nothing Then
oDoc.PrintOut
oDoc.Save = True
oDoc.Close
End If

oWrd.Quit
End Function

Thanks for your time and help. It is surely appreciated
 
J

John Nurick

Hi Joanne,

I can't see anything in your code that would cause this, so the first
thing is to make certain that there isn't a left-over Word locking file.
These can easily get left behind if Word crashes or is forced to close.
If you double-click on the Word document in Windows Explorer, does it
open normally? If not, delete any temporary files in the same folder.
Word usually puts ~ characters in their names; for more information see
http://word.mvps.org or the Microsoft knowledgebase.

One line in your code that I'd expect to cause a problem is
oDoc.Save = True
which should just be
oDoc.Save
 

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

Similar Threads


Top