Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
rds rds is offline
external usenet poster
 
Posts: 8
Default 'addrow' VB macro error: requested member of collection does not e

I am using a VB macro in Word 2003 to allow users to add rows to multiple
tables in a protected form while copying the existing form fields in the new
row. I used code posted to another site from a Word MVP (thank you Jay
Freedman!) as I am completely new to VB. I suddenly started getting an error
message when trying to add new rows to any table in the document: "The
requested member of the collection does not exist".

Is the cause for the error that some of my tables have merged cells? Is
there a way to revise the code to allow merged cells (as I can't work around
them)? Is there any general revisions to ensure users can avoid the error
message?


Sub addrow()
Dim response As Integer
Dim myRow As Long
Dim myCount As Long
Dim colCount As Long
Dim colIndex As Long
Dim myNewField As String

If Not Selection.Information(wdWithInTable) Then
Exit Sub
End If

response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
ActiveDocument.Unprotect

colCount = Selection.Tables(1).Columns.Count

Selection.InsertRowsBelow 1
Selection.Collapse (wdCollapseStart)
myRow = Selection.Information(wdStartOfRangeRowNumber)

For colIndex = 1 To colCount - 1
Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colIndex & "row" & myRow
..Enabled = True
End With
Selection.MoveRight Unit:=wdCell
Next colIndex

Selection.FormFields.Add Range:=Selection.Range, _
Type:=wdFieldFormTextInput
myCount = ActiveDocument.Range.FormFields.Count
With ActiveDocument.FormFields(myCount)
..Name = "text" & colCount & "row" & myRow
..Enabled = True
..ExitMacro = "addrow"
End With
myNewField = "text1row" & myRow
ActiveDocument.Protect NoReset:=True, _
Type:=wdAllowOnlyFormFields
ActiveDocument.Range.FormFields(myNewField).Select
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.word.tables
David Sisson David Sisson is offline
external usenet poster
 
Location: Deep southern US
Posts: 3
Default 'addrow' VB macro error: requested member of collection does note

When you get the error, Click Debug and show us which line it is on.
  #3   Report Post  
Posted to microsoft.public.word.tables
rds rds is offline
external usenet poster
 
Posts: 8
Default 'addrow' VB macro error: requested member of collection does n

Ok, I think it has issues with Line 8 (the blank space between 'Dim
myNewField As String' and 'If Not Selection.Information(wdWithInTable)
Then'). I did also get a runtime error, #5941, with the same error message
once. As I am very new to VB any help with how best to debug would be
appreciated. (I just ran the script from the VB editor.)

The error only occurs when you select 'Yes' to add a new row. If you decline
there is no error message.

I also found that new row does not retain any of the field settings (i.e.
dropdowns) from the previous line, including the 'addrow' macro. It would
be best if the fields could be copied exactly into the new row, especially as
the user will not expect to have to go back 'up' to expand the table.

Thanks!
  #4   Report Post  
Posted to microsoft.public.word.tables
rds rds is offline
external usenet poster
 
Posts: 8
Default 'addrow' VB macro error: requested member of collection does n

Just a note: The macro is embedded directly into the document as it is the
only one needed.
  #5   Report Post  
Posted to microsoft.public.word.tables
rds rds is offline
external usenet poster
 
Posts: 8
Default 'addrow' VB macro error: requested member of collection does n

Also, question regarding this macro and the use of document protection: If I
password protect the document (as it will be circulated to many users) will
there be any negative affects on the Macro? The protection would be to limit
users to only being able to fill in the form fields.
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
Formal invitation to become member of a publication maria Microsoft Word Help 1 November 30th 07 10:01 AM
Method or Data Member not found HELP Kenny Microsoft Word Help 1 September 21st 07 05:18 PM
Error# 5852 Requested Object Is Not Available [email protected] Mailmerge 5 June 28th 06 10:07 PM
MVB error- compile error method or data member not found jvb70 Microsoft Word Help 0 July 29th 05 05:39 PM
Error 5941 - The requested member of the collection does not exsis Melisa Microsoft Word Help 3 July 13th 05 03:56 PM


All times are GMT +1. The time now is 11:45 AM.

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"