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

I

Ivan Nue

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
 
C

Cindy M -WordMVP-

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
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.

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 :)
 
I

Ivan Nue

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
 
I

Ivan Nue

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
 
P

Peter Jamieson

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...
 

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