ACTEBS
actebs at actebs.com.au
Tue Nov 9 09:14:13 CST 2004
Brian,
I wish I had known about the Exists property.
I figured out a solution where I created a table that housed the names of the bookmarks I was looking for, then I pass the recordset to the function and if it errors out with 5941 I trap it and know the BM is not there. It's quick and dirty, but does the job. The result is the following: (Hopefully it will help someone else)
Function FindBMark(strWordDocPath As String, mRst As DAO.Recordset) As Boolean
On Error GoTo Err_FindBMark
Dim WordObj As Word.Application
FindBMark = True
gBMark = True
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open strWordDocPath
WordObj.Visible = False
' Find the bookmark
mRst.MoveFirst
Do Until mRst.EOF
With mRst
WordObj.ActiveDocument.Bookmarks(!FieldToCheck).Select
End With
mRst.MoveNext
Loop
' Close the document.
WordObj.ActiveDocument.Close
' Quit Microsoft Word and clean up
WordObj.Quit
Set WordObj = Nothing
Exit_FindBMark:
Exit Function
Err_FindBMark:
Select Case Err
Case 5941
FindBMark = False
gBMark = False
WordObj.ActiveDocument.Close
WordObj.Quit
Set WordObj = Nothing
Case Else
MsgBox Err.Description
Resume Exit_FindBMark
End Select
End Function
Thanks Brian, I'll use your suggestion somewhere else in the app, you've saved me a bit of coding.
Vlad
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Bryan
Carbonnell
Sent: Wednesday, 10 November 2004 1:45 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Word Docs Bookmark Check
On Tue, 9 Nov 2004 16:19:43 +1100, ACTEBS <actebs at actebs.com.au> wrote:
> Before I merge I need to check whether all the bookmarks in the doc exist, otherwise the wrong document has been selected for that activity...
Vlad,
I'm not sure how you are correlating your bookmarks with what the user
chooses, but you can use a line like:
doc.Bookmarks.Exists("BookmarkName")
to see if the bookmark exists in the document that you are working
with, assuming of course, that the doc variable references the Word
document that you are working with.
--
Bryan Carbonnell - carbonnb at gmail.com
Life's journey is not to arrive at the grave safely in a well
preserved body, but rather to skid in sideways, totally worn out,
shouting "What a great ride!"
--
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com