Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / November 2003

Tip: Looking for answers? Try searching our database.

Document.Fields.Locked = false locks Word 97 on XP Home during automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ivan Nue - 21 Oct 2003 02:23 GMT
I have a computer running XP Home, Word 97 SR-2B, automated in the
background preparing for a mail merge.  I execute the
document.fields.locked = false command to ensure that the fields are
not locked, and they're not in this particular document that I am
testing with.  Now, I haven't seen this problem before, but this
process is routine in this office.  On this new system, Word locks up
during automation on this Locked = false command.  If I write a Word
macro to include this command from within the same document, it runs
fine as always.  I am confused.

If anyone has any idea why this is happening, I'd love to hear it.

Thank you.

Ivan Nue
Cindy M  -WordMVP- - 27 Oct 2003 19:50 GMT
Hi Ivan,

Well... there is no such thing in Word VBA as
   document.fields.locked

It would have to be either ThisDocument or ActiveDocument. If it's the
former you're using, I can see where this could be a problem, as it
would be trying to execute the code in the "container" holding the
code. And if that "container" is not the same as the document you're
trying to automate, you're in trouble.

We could help you a lot better if you
- copied in the code you're actually using, along with all variable
declarations
- tell us what is "holding" the code: a COM addin, an addin template,
the template used to create the merge documents, other?

> I have a computer running XP Home, Word 97 SR-2B, automated in the
> background preparing for a mail merge.  I execute the
[quoted text clipped - 5 lines]
> macro to include this command from within the same document, it runs
> fine as always.  I am confused.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Ivan Nue - 21 Nov 2003 00:40 GMT
Now, I've enclosed below the code that reproduces the behavior I
mentioned earlier (the operating system Word is running on seems to be
irrelevant).

I've reduced the mail merge document that is giving me all the trouble
to just the merge fields and codes that still cause the code below to
hang while unlocking the fields.  This document has as its datasource
a view from SQL Server.  The problem doesn't occur with other
datasources.  This mailmerge document, which I can provide upon
request, simply contains the following "word code:"

{ IF { REF SPCheck } = { MERGEFIELD Salesperson_FID } { IF { MergeRec
} = "1" "" }  "some text here" } {SET SPCheck { MERGEFIELD
Salesperson_FID}}{IF { REF DateCheck \* MERGEFORMAT } = "{ MERGEFIELD
Date_Call_Due }{ MERGEFIELD Salesperson_FID }" { IF { MergeRec } = "1"
{ MERGEFIELD Date_Call_Due }} "{ MERGEFIELD Date_Call_Due }" } { SET
DateCheck "{ MERGEFIELD Date_Call_Due }{ MERGEFIELD Salesperson_FID}"
}

Here's the VB code that causes the test.doc document to hang on the
"Unlocking Template Fields" section.

Any help is greatly appreciated,

Ivan

Option Explicit

Sub Command1_Click()

   Dim oWordApp                          As Object 'Word.Application
   Dim oTemplateDoc                      As Object 'Word.Document
   Dim sFullDocName                      As String
   Dim oWordField                        As Object 'Word.Field
   Dim oWordShape                        As Object 'Word.Shape
   Dim oWordGroup                        As Object 'Word.Shape
   Dim oWordRange                        As Object 'Word.Range
   Dim colGroups                         As New Collection
   Dim sFieldName                        As String
   
   Dim bOrigCheckSpelling                As Boolean
   Dim bOrigCheckGrammar                 As Boolean

   Const wdDoNotSaveChanges              As Long = 0

   Command1.Enabled = False

'45 minute timeout
   App.OleRequestPendingTimeout = 2700000
   
'Generate the proper full file path name for the Word document
   sFullDocName = App.Path & "\test"
   
   Me.Caption = "Launching instance of Microsoft Word..."
   DoEvents

' Create an instance of Microsoft Word
   Set oWordApp = CreateObject("Word.Application")
       
   oWordApp.Visible = True
       
   Me.Caption = "Opening correspondence template..."
   DoEvents
   
   Set oTemplateDoc = oWordApp.Documents.Open(sFullDocName & ".doc",
, True)

   Me.Caption = "Unlocking Template Data Fields... freezes here in
Word97..."
   DoEvents
   oTemplateDoc.Fields.Locked = False
   
   Me.Caption = "Quitting Word..."
   DoEvents
   oWordApp.Quit wdDoNotSaveChanges
   Me.Caption = "Done"
   Command1.Enabled = True
   DoEvents

End Sub

> Hi Ivan,
>
[quoted text clipped - 30 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
Ivan Nue - 25 Nov 2003 21:19 GMT
Now, I've enclosed below the code that reproduces the behavior I
mentioned earlier (the operating system Word is running on seems to be
irrelevant).

I've reduced the mail merge document that is giving me all the trouble
to just the merge fields and codes that still cause the code below to
hang while unlocking the fields.  This document has as its datasource
a view from SQL Server.  The problem doesn't occur with other
datasources.  This mailmerge document, which I can provide upon
request, simply contains the following "word code:"

{ IF { REF SPCheck } = { MERGEFIELD Salesperson_FID } { IF { MergeRec
} = "1" "" }  "some text here" } {SET SPCheck { MERGEFIELD
Salesperson_FID}}{IF { REF DateCheck \* MERGEFORMAT } = "{ MERGEFIELD
Date_Call_Due }{ MERGEFIELD Salesperson_FID }" { IF { MergeRec } = "1"
{ MERGEFIELD Date_Call_Due }} "{ MERGEFIELD Date_Call_Due }" } { SET
DateCheck "{ MERGEFIELD Date_Call_Due }{ MERGEFIELD Salesperson_FID}"
}

Here's the VB code that causes the test.doc document to hang on the
"Unlocking Template Fields" section.

Any help is greatly appreciated,

Ivan

Option Explicit

Sub Command1_Click()

   Dim oWordApp                          As Object 'Word.Application
   Dim oTemplateDoc                      As Object 'Word.Document
   Dim sFullDocName                      As String
   Dim oWordField                        As Object 'Word.Field
   Dim oWordShape                        As Object 'Word.Shape
   Dim oWordGroup                        As Object 'Word.Shape
   Dim oWordRange                        As Object 'Word.Range
   Dim colGroups                         As New Collection
   Dim sFieldName                        As String
   
   Dim bOrigCheckSpelling                As Boolean
   Dim bOrigCheckGrammar                 As Boolean

   Const wdDoNotSaveChanges              As Long = 0

   Command1.Enabled = False

'45 minute timeout
   App.OleRequestPendingTimeout = 2700000
   
'Generate the proper full file path name for the Word document
   sFullDocName = App.Path & "\test"
   
   Me.Caption = "Launching instance of Microsoft Word..."
   DoEvents

' Create an instance of Microsoft Word
   Set oWordApp = CreateObject("Word.Application")
       
   oWordApp.Visible = True
       
   Me.Caption = "Opening correspondence template..."
   DoEvents
   
   Set oTemplateDoc = oWordApp.Documents.Open(sFullDocName & ".doc",
, True)

   Me.Caption = "Unlocking Template Data Fields... freezes here in
Word97..."
   DoEvents
   oTemplateDoc.Fields.Locked = False
   
   Me.Caption = "Quitting Word..."
   DoEvents
   oWordApp.Quit wdDoNotSaveChanges
   Me.Caption = "Done"
   Command1.Enabled = True
   DoEvents

End Sub

Cindy M  -WordMVP- <C.Meister-C@hispeed.chwrote in message news:<VA.00008953.0080e83e@speedy>...
> Hi Ivan,
>
[quoted text clipped - 30 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
Peter Jamieson - 26 Nov 2003 09:42 GMT
Hi Ivan,

First, I tried your VB on a Win98/Word 97 box, but running as a Word VBA
macro and a few lines commented out.
I noticed that the

    oTemplateDoc.Fields.Locked = False

line fails (application or object-defined error) if oTemplateDoc is declared
As Object, but succeeds if it is declared As Word.Document.

I feel sure a proper VB(A) person ought to be able to tell you why this
happens (and perhaps it doesn't happen in VB, only VBA). I couldn't find
anything relevant searching the groups, which seemed strange given it looks
like a problem that would pop up a lot. But I wonder whether it has any
bearing on your problem, particularly since untrapped errors in an automated
object will probably cause it to hang. Doesn't explain why the problem only
occurs with the SQL Server data source either of course...

--
Peter Jamieson - Word MVP

> Now, I've enclosed below the code that reproduces the behavior I
> mentioned earlier (the operating system Word is running on seems to be
[quoted text clipped - 111 lines]
> > This reply is posted in the Newsgroup; please post any follow question
> > or reply in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.