Discussion:
"Member of collection does not exist"--so? Go on with it!
(too old to reply)
Angyl
2006-05-17 22:58:02 UTC
Permalink
I've got one document with fields filling in another document with fields.

MULTIPLE documents, in fact.

Some of the documents it is filling in, do not have all of the fields, so I
get the error message:

"runtime error 5941" "the requested member of the collection does not
exist"

How do I tell VB to "chill" and go on with its work if "the requested member
of the collection does not exist?"
Jean-Guy Marcil
2006-05-18 00:49:11 UTC
Permalink
Post by Angyl
I've got one document with fields filling in another document with fields.
MULTIPLE documents, in fact.
Some of the documents it is filling in, do not have all of the
"runtime error 5941" "the requested member of the collection does not
exist"
How do I tell VB to "chill" and go on with its work if "the requested
member of the collection does not exist?"
And the code you are using is....
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
***@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Angyl
2006-05-18 15:09:01 UTC
Permalink
Here's a smattering of my code (it is long since there is a line for every
field in the document)

Sub PaperWork()
response = MsgBox("Print Set Up Paperwork Now?", vbQuestion + vbYesNo)
If response = vbYes Then
Dim X As Long
On Error GoTo 0
X = ActiveDocument.FormFields("Employees").Result
CN = ActiveDocument.FormFields("ClientName").Result
Documents.Open ("S:\Sales\Setup Sheet.doc")

ActiveDocument.FormFields("ClientName").Result = CN
ActiveDocument.PrintOut Copies:=X

End If
End Sub

The problem, once again, is that this is supposed to open a lot of different
documents, fill them in, and print them, and not all of the documents have
all of the fields so I would get that error message if, for example
"ClientName" didn't exist in a document.
Post by Jean-Guy Marcil
Post by Angyl
I've got one document with fields filling in another document with fields.
MULTIPLE documents, in fact.
Some of the documents it is filling in, do not have all of the
"runtime error 5941" "the requested member of the collection does not
exist"
How do I tell VB to "chill" and go on with its work if "the requested
member of the collection does not exist?"
And the code you are using is....
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
Word MVP site: http://www.word.mvps.org
Jezebel
2006-05-18 02:20:23 UTC
Permalink
on error resume next
myVar = Collection("Member")
if err.number <> 0 then
myVar = "UNDEFINED"
end if
on error goto 0
Post by Angyl
I've got one document with fields filling in another document with fields.
MULTIPLE documents, in fact.
Some of the documents it is filling in, do not have all of the fields, so I
"runtime error 5941" "the requested member of the collection does not
exist"
How do I tell VB to "chill" and go on with its work if "the requested member
of the collection does not exist?"
Angyl
2006-05-18 15:11:02 UTC
Permalink
Thanks, Jezebel!

Error message, though:
Compile Error:
Sub or Function not defined

On the line

myVar = Collection("Member")

It's highlighting the word "collection"

???
Post by Jezebel
on error resume next
myVar = Collection("Member")
if err.number <> 0 then
myVar = "UNDEFINED"
end if
on error goto 0
Post by Angyl
I've got one document with fields filling in another document with fields.
MULTIPLE documents, in fact.
Some of the documents it is filling in, do not have all of the fields, so I
"runtime error 5941" "the requested member of the collection does not
exist"
How do I tell VB to "chill" and go on with its work if "the requested member
of the collection does not exist?"
WalterContrata
2006-05-18 16:02:00 UTC
Permalink
In Jezebel's code, collection stands for whatever collection you are
using. For example, ActiveDocument.FormFields("ClientName").


'If an error occurs on subsequent lines, don't report the message.
' skip the error-causing statement and go to the
next statement
On Error Resume Next

ActiveDocument.FormFields("ClientName").Result = CN
'If an error occurs on subsequent lines, report the error message.
On Error GoTo 0
Angyl
2006-05-18 16:29:02 UTC
Permalink
THAT makes sense! Thanks, it worked!
Post by WalterContrata
In Jezebel's code, collection stands for whatever collection you are
using. For example, ActiveDocument.FormFields("ClientName").
'If an error occurs on subsequent lines, don't report the message.
' skip the error-causing statement and go to the
next statement
On Error Resume Next
ActiveDocument.FormFields("ClientName").Result = CN
'If an error occurs on subsequent lines, report the error message.
On Error GoTo 0
Continue reading on narkive:
Loading...