#1   Report Post  
Leonard
 
Posts: n/a
Default Calling Cindy Meister

Hello Ms. Cindy Meister. When I ran your following macro (via a MACROBUTTON)
in a protected form and I typed a search phrase, I got a Microsoft Visual
Basic error message that said "Run-time error '5941'; The requested member of
the collection does not exist." When I clicked Debug, the line "Set ffld
= doc.FormFields(Selection.Bookmarks(1).Name)" within the macro was hi-lited
in yellow.

Ms. Meister, why was I doing wrong?
_______________________

Sub FindInForm()
Dim doc As Word.Document, ffld As Word.FormField
Dim szFindTerm As String, lPos As Long
Dim szSearchString As String, rng As Word.Range
Dim rngStart As Word.Range, lNumFfld As Long
Dim lFfldCounter As Long

Set doc = ActiveDocument
szFindTerm = InputBox("Enter the phrase you wish to find:")
lNumFfld = doc.FormFields.Count
lFfldCounter = 0
Set ffld = doc.FormFields(Selection.Bookmarks(1).Name)
If Len(szFindTerm) = 0 Then Exit Sub
Set rngStart = Selection.Range
Set rng = rngStart.Duplicate
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
Do
Set ffld = ffld.Next
If ffld Is Nothing Then
Set ffld = ActiveDocument.FormFields(1)
End If
If rngStart.InRange(ffld.Range) Then
MsgBox "All form fields were searched; the phrase was not found."
Exit Sub
End If
ffld.Select
Selection.Collapse
Set rng = Selection.Range
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
lFfldCounter = lFfldCounter + 1
Loop Until lFfldCounter = lNumFfld
End Sub


  #2   Report Post  
Anne Troy
 
Posts: n/a
Default Calling Cindy Meister

Just a wild guess until Cindy comes along. I think it means it didn't find
any bookmarks in your document.
************
Anne Troy
www.OfficeArticles.com

"Leonard" wrote in message
...
Hello Ms. Cindy Meister. When I ran your following macro (via a
MACROBUTTON)
in a protected form and I typed a search phrase, I got a Microsoft Visual
Basic error message that said "Run-time error '5941'; The requested member
of
the collection does not exist." When I clicked Debug, the line "Set
ffld
= doc.FormFields(Selection.Bookmarks(1).Name)" within the macro was
hi-lited
in yellow.

Ms. Meister, why was I doing wrong?
_______________________

Sub FindInForm()
Dim doc As Word.Document, ffld As Word.FormField
Dim szFindTerm As String, lPos As Long
Dim szSearchString As String, rng As Word.Range
Dim rngStart As Word.Range, lNumFfld As Long
Dim lFfldCounter As Long

Set doc = ActiveDocument
szFindTerm = InputBox("Enter the phrase you wish to find:")
lNumFfld = doc.FormFields.Count
lFfldCounter = 0
Set ffld = doc.FormFields(Selection.Bookmarks(1).Name)
If Len(szFindTerm) = 0 Then Exit Sub
Set rngStart = Selection.Range
Set rng = rngStart.Duplicate
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
Do
Set ffld = ffld.Next
If ffld Is Nothing Then
Set ffld = ActiveDocument.FormFields(1)
End If
If rngStart.InRange(ffld.Range) Then
MsgBox "All form fields were searched; the phrase was not found."
Exit Sub
End If
ffld.Select
Selection.Collapse
Set rng = Selection.Range
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
lFfldCounter = lFfldCounter + 1
Loop Until lFfldCounter = lNumFfld
End Sub




  #3   Report Post  
Leonard
 
Posts: n/a
Default Calling Cindy Meister

Anne, thanks for your contribution which I have always appreciated in the
past. Hmmmm...I used the Form toolbar to create all of the text fields,
therefore a bookmark was automatically assigned by Word 2002 to each of the
text fields. I could recheck wach text field to see if any of them does not
have a bookmark assigned to it. So, it's possible Cindy's macro stopped
running because all text fields have to have a bookmark assigned to it in
order for a user to perform a word/phrase find?

I had thought that I could not protect the form with a password or that I
had to use beginning and ending quotatioj marks to surround the word or
phrase, but I still got the same error message.

What was I doing wrong? I would love to have this macro run properly for my
customers would love to be able to conduct a Find on their completed form
fields.

"Anne Troy" wrote:

Just a wild guess until Cindy comes along. I think it means it didn't find
any bookmarks in your document.
************
Anne Troy
www.OfficeArticles.com

"Leonard" wrote in message
...
Hello Ms. Cindy Meister. When I ran your following macro (via a
MACROBUTTON)
in a protected form and I typed a search phrase, I got a Microsoft Visual
Basic error message that said "Run-time error '5941'; The requested member
of
the collection does not exist." When I clicked Debug, the line "Set
ffld
= doc.FormFields(Selection.Bookmarks(1).Name)" within the macro was
hi-lited
in yellow.

Ms. Meister, why was I doing wrong?
_______________________

Sub FindInForm()
Dim doc As Word.Document, ffld As Word.FormField
Dim szFindTerm As String, lPos As Long
Dim szSearchString As String, rng As Word.Range
Dim rngStart As Word.Range, lNumFfld As Long
Dim lFfldCounter As Long

Set doc = ActiveDocument
szFindTerm = InputBox("Enter the phrase you wish to find:")
lNumFfld = doc.FormFields.Count
lFfldCounter = 0
Set ffld = doc.FormFields(Selection.Bookmarks(1).Name)
If Len(szFindTerm) = 0 Then Exit Sub
Set rngStart = Selection.Range
Set rng = rngStart.Duplicate
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
Do
Set ffld = ffld.Next
If ffld Is Nothing Then
Set ffld = ActiveDocument.FormFields(1)
End If
If rngStart.InRange(ffld.Range) Then
MsgBox "All form fields were searched; the phrase was not found."
Exit Sub
End If
ffld.Select
Selection.Collapse
Set rng = Selection.Range
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
lFfldCounter = lFfldCounter + 1
Loop Until lFfldCounter = lNumFfld
End Sub





  #4   Report Post  
Jay Freedman
 
Posts: n/a
Default Calling Cindy Meister

Hi Leonard,

This is, like Anne's reply, just a guess...

Yes, Cindy's macro assumes that every form field has an associated
bookmark. Normally, when you create a form field, Word automatically
assigns a bookmark to serve as its name.

If you used the button on the Forms toolbar to create one form field,
but then you copied that field and pasted to make more copies of it,
the copies won't have bookmarks associated with them. This is a side
effect of the fact that Word allows only one occurrence of any
bookmark name per document. As you do each paste, that field grabs the
bookmark and the older ones are left nameless.

Look in the Properties dialog of each form field. If the Bookmark box
is blank, enter a unique name. Then reprotect the document and try the
macro.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Tue, 25 Oct 2005 04:25:02 -0700, "Leonard"
wrote:

Anne, thanks for your contribution which I have always appreciated in the
past. Hmmmm...I used the Form toolbar to create all of the text fields,
therefore a bookmark was automatically assigned by Word 2002 to each of the
text fields. I could recheck wach text field to see if any of them does not
have a bookmark assigned to it. So, it's possible Cindy's macro stopped
running because all text fields have to have a bookmark assigned to it in
order for a user to perform a word/phrase find?

I had thought that I could not protect the form with a password or that I
had to use beginning and ending quotatioj marks to surround the word or
phrase, but I still got the same error message.

What was I doing wrong? I would love to have this macro run properly for my
customers would love to be able to conduct a Find on their completed form
fields.

"Anne Troy" wrote:

Just a wild guess until Cindy comes along. I think it means it didn't find
any bookmarks in your document.
************
Anne Troy
www.OfficeArticles.com

"Leonard" wrote in message
...
Hello Ms. Cindy Meister. When I ran your following macro (via a
MACROBUTTON)
in a protected form and I typed a search phrase, I got a Microsoft Visual
Basic error message that said "Run-time error '5941'; The requested member
of
the collection does not exist." When I clicked Debug, the line "Set
ffld
= doc.FormFields(Selection.Bookmarks(1).Name)" within the macro was
hi-lited
in yellow.

Ms. Meister, why was I doing wrong?
_______________________

Sub FindInForm()
Dim doc As Word.Document, ffld As Word.FormField
Dim szFindTerm As String, lPos As Long
Dim szSearchString As String, rng As Word.Range
Dim rngStart As Word.Range, lNumFfld As Long
Dim lFfldCounter As Long

Set doc = ActiveDocument
szFindTerm = InputBox("Enter the phrase you wish to find:")
lNumFfld = doc.FormFields.Count
lFfldCounter = 0
Set ffld = doc.FormFields(Selection.Bookmarks(1).Name)
If Len(szFindTerm) = 0 Then Exit Sub
Set rngStart = Selection.Range
Set rng = rngStart.Duplicate
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
Do
Set ffld = ffld.Next
If ffld Is Nothing Then
Set ffld = ActiveDocument.FormFields(1)
End If
If rngStart.InRange(ffld.Range) Then
MsgBox "All form fields were searched; the phrase was not found."
Exit Sub
End If
ffld.Select
Selection.Collapse
Set rng = Selection.Range
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
lFfldCounter = lFfldCounter + 1
Loop Until lFfldCounter = lNumFfld
End Sub





  #5   Report Post  
Anne Troy
 
Posts: n/a
Default Calling Cindy Meister

Yup. Just a guess. I've gotten this error on other macros that worked with
bookmarks and the cause was...no bookmarks. I've got this book:
http://www.amazon.com/gp/product/193...oks&v=glanc e
on my desktop--just submitted my final review before publishing. Five macros
in it written by Cindy that deal with forms and form fields. But that one's
not in it!!
(
************
Anne Troy
www.OfficeArticles.com

"Jay Freedman" wrote in message
...
Hi Leonard,

This is, like Anne's reply, just a guess...

Yes, Cindy's macro assumes that every form field has an associated
bookmark. Normally, when you create a form field, Word automatically
assigns a bookmark to serve as its name.

If you used the button on the Forms toolbar to create one form field,
but then you copied that field and pasted to make more copies of it,
the copies won't have bookmarks associated with them. This is a side
effect of the fact that Word allows only one occurrence of any
bookmark name per document. As you do each paste, that field grabs the
bookmark and the older ones are left nameless.

Look in the Properties dialog of each form field. If the Bookmark box
is blank, enter a unique name. Then reprotect the document and try the
macro.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

On Tue, 25 Oct 2005 04:25:02 -0700, "Leonard"
wrote:

Anne, thanks for your contribution which I have always appreciated in the
past. Hmmmm...I used the Form toolbar to create all of the text fields,
therefore a bookmark was automatically assigned by Word 2002 to each of
the
text fields. I could recheck wach text field to see if any of them does
not
have a bookmark assigned to it. So, it's possible Cindy's macro stopped
running because all text fields have to have a bookmark assigned to it in
order for a user to perform a word/phrase find?

I had thought that I could not protect the form with a password or that I
had to use beginning and ending quotatioj marks to surround the word or
phrase, but I still got the same error message.

What was I doing wrong? I would love to have this macro run properly for
my
customers would love to be able to conduct a Find on their completed form
fields.

"Anne Troy" wrote:

Just a wild guess until Cindy comes along. I think it means it didn't
find
any bookmarks in your document.
************
Anne Troy
www.OfficeArticles.com

"Leonard" wrote in message
...
Hello Ms. Cindy Meister. When I ran your following macro (via a
MACROBUTTON)
in a protected form and I typed a search phrase, I got a Microsoft
Visual
Basic error message that said "Run-time error '5941'; The requested
member
of
the collection does not exist." When I clicked Debug, the line
"Set
ffld
= doc.FormFields(Selection.Bookmarks(1).Name)" within the macro was
hi-lited
in yellow.

Ms. Meister, why was I doing wrong?
_______________________

Sub FindInForm()
Dim doc As Word.Document, ffld As Word.FormField
Dim szFindTerm As String, lPos As Long
Dim szSearchString As String, rng As Word.Range
Dim rngStart As Word.Range, lNumFfld As Long
Dim lFfldCounter As Long

Set doc = ActiveDocument
szFindTerm = InputBox("Enter the phrase you wish to find:")
lNumFfld = doc.FormFields.Count
lFfldCounter = 0
Set ffld = doc.FormFields(Selection.Bookmarks(1).Name)
If Len(szFindTerm) = 0 Then Exit Sub
Set rngStart = Selection.Range
Set rng = rngStart.Duplicate
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
Do
Set ffld = ffld.Next
If ffld Is Nothing Then
Set ffld = ActiveDocument.FormFields(1)
End If
If rngStart.InRange(ffld.Range) Then
MsgBox "All form fields were searched; the phrase was not
found."
Exit Sub
End If
ffld.Select
Selection.Collapse
Set rng = Selection.Range
rng.End = ffld.Range.End
szSearchString = rng.Text
Debug.Print szSearchString
lPos = InStr(ffld.Result, szFindTerm)
If lPos 0 Then
Selection.MoveStart wdCharacter, lPos - 1
Selection.MoveEnd wdCharacter, Len(szFindTerm)
Exit Sub
End If
lFfldCounter = lFfldCounter + 1
Loop Until lFfldCounter = lNumFfld
End Sub







Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a sub with argument in VBA Pyth007 Microsoft Word Help 0 July 22nd 05 08:29 PM
Calling all Wizards! stephanie Microsoft Word Help 6 June 2nd 05 07:26 AM
How do I create a Calling document Derek Microsoft Word Help 3 May 19th 05 01:28 AM
Calling out comments Opinicus Microsoft Word Help 4 February 24th 05 04:40 PM


All times are GMT +1. The time now is 03:33 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"