"Member of collection does not exist"--so? Go on with it!

A

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
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?"
 
J

Jean-Guy Marcil

Angyl was telling us:
Angyl nous racontait que :
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?"

And the code you are using is....

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jezebel

on error resume next
myVar = Collection("Member")
if err.number <> 0 then
myVar = "UNDEFINED"
end if
on error goto 0
 
A

Angyl

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

Angyl

Thanks, Jezebel!

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

On the line

myVar = Collection("Member")

It's highlighting the word "collection"

???
 
W

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
 

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