?
Solved

Requested member of the collection does not exist

Posted on 2004-03-25
11
Medium Priority
?
1,512 Views
Last Modified: 2007-12-19
My app is raising the following exception:

BOOKMARK LOOP EXCEPTION:  Message:  The requested member of the collection does not exist.--Stack Trace:     at Word.Tables.Item(Int32 Index)
   at BuyersFund.FaxCOM.FaxCOM.LoopThroughGiftLetterBookmarks(_Document oDoc, DataRow myDataRow) in n:\clientdevelopment\neo\buyersfund\faxcom\faxcom.cs:line 746
   at BuyersFund.FaxCOM.FaxCOM.CreateDocument() in n:\clientdevelopment\neo\buyersfund\faxcom\faxcom.cs:line 602
END, timestamp:  3/25/2004 4:27:30 PM


Here is line 746

rng.Tables.Item(0).Rows.AllowBreakAcrossPages = 1;



I am assuming the problem is with AllowBreakAcrossPages  (something wrong with my syntax?)

What I don't understand is why does AllowBreakAcrossPages (and other available properties and methods) show up when I invoke the code completion on rng.Tables.Item(0).Rows.  ?
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 10682896
Are you sure that rng.Tables.Item(0) is returning anything?  Maybe there are no tables coming up?  What is the value of rng.Tables.Count at that point?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 10682957
What is the value of rng.Tables.Count at that point?

1


According to this:


http://www.knowltonfamily.com/tables_count.gif

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 10682960
Is Item(int Index)    0 based    or 1 based?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:eternal_21
ID: 10683015
I don't know, but I would assume that it is 0 based.

Try this:

  Word.Table table;
  table = rng.Tables.Item(0);
  table.Rows.AllowBreakAcrossPages = 1;

Break on the third row, and see if table is null, or if it is assigned.
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 10683026
If it comes up null go ahead and try,
  table = rng.Tables.Item(1);
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 10683041
It's not getting to the third line.

The second line is throwing an exception:


BOOKMARK LOOP EXCEPTION:  Message:  The requested member of the collection does not exist.--Stack Trace:     at Word.Tables.Item(Int32 Index)
   at BuyersFund.FaxCOM.FaxCOM.LoopThroughGiftLetterBookmarks(_Document oDoc, DataRow myDataRow) in n:\clientdevelopment\neo\buyersfund\faxcom\faxcom.cs:line 747
   at BuyersFund.FaxCOM.FaxCOM.CreateDocument() in n:\clientdevelopment\neo\buyersfund\faxcom\faxcom.cs:line 602
END, timestamp:  3/25/2004 5:05:42 PM




So the problem is HERE:

 table = rng.Tables.Item(0);
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 10683068
UPDATE:

I changed

table = rng.Tables.Item(0);

to

table = rng.Tables.Item(1);


and line 2 is okay now.


~~~~~~~~~~~~~~~~~~~~~~~~~

But an exception is thrown on the next line:

table.Rows.AllowBreakAcrossPages = 1;


BOOKMARK LOOP EXCEPTION:  Message:  The parameter is incorrect.--Stack Trace:     at Word.Rows.set_AllowBreakAcrossPages(Int32 prop)
   at BuyersFund.FaxCOM.FaxCOM.LoopThroughGiftLetterBookmarks(_Document oDoc, DataRow myDataRow) in n:\clientdevelopment\neo\buyersfund\faxcom\faxcom.cs:line 748
   at BuyersFund.FaxCOM.FaxCOM.CreateDocument() in n:\clientdevelopment\neo\buyersfund\faxcom\faxcom.cs:line 602


0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 10683081


table.Rows.AllowBreakAcrossPages = -1;


instead of


table.Rows.AllowBreakAcrossPages = 1;



?????


Seems to have corrected the problem....
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 2000 total points
ID: 10684566
I have done some testing here, and to answer your earlier question the Item indexes are definately 1-based (not 0-based).

In VBA (well, these objects specifically) true is represented by -1, and false as 0.  That is why AllowBreakAcrossPages = -1 works!
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 10685059
Can you post some more code. Is this code in a loop?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 10688318
TheAvenger:

FYI:  I think this problem is solved now.  The code below does not
generate an exception.

Yes, the code is in a loop.  I probably don't need to post it, since I think it is working now, but maybe something else will stand-out:


private void LoopThroughGiftLetterBookmarks(Word._Document oDoc,DataRow myDataRow)
            {                  

                  string strFullBookmarkName="";
                  string strInstanceValue="";
                  string Field_Name="";
                  bool useExceptionBlock = false;
                  string tempScalarSQL = "";
                  int c = 0;            
                  long numGrants = 0;
                  


                  for(c = 0;c<intBookmarkCount;c++)
                  {
                        Field_Name = bookmarkFuncs.ExtractFieldNameFromBookmark(bookMarkArray[c]);                                    
                                   
                        // This works just as well as iterating through all the rows, if it doesn't exist it gracefully continues to the next bookmark
                        try
                        {
                              if(myDataRow[Field_Name.ToUpper()] != null)
                              {
                                    useExceptionBlock = false;
                                    object oBookmarkName = bookMarkArray[c];
                                    strFullBookmarkName = bookMarkArray[c];
                                    strInstanceValue = myDataRow[Field_Name].ToString();;

                                    switch(Field_Name)
                                    {
                                          case("City"):
                                                strInstanceValue += ",";
                                                break;
                                          case ("TCD"):
                                                strInstanceValue = DateTime.Parse(strInstanceValue).ToShortDateString();
                                                break;
                                          case("TitleFax"):
                                          case("workNumber"):
                                          case("FaxNumber"):
                                                strInstanceValue = formatLIB.FormatAsPhoneNumber(strInstanceValue);
                                                break;
                                          case("GrantAmount"):
                                          case("SSFAmount"):
                                          case("MPMonthlyAmount"):
                                                strInstanceValue = "$" + formatLIB.FormatAsCurrency(strInstanceValue).ToString();
                                                if(strInstanceValue == "$0")
                                                {
                                                      strInstanceValue = "";
                                                }
                                                break;
                                          case("MPSSN"):
                                                strInstanceValue = formatLIB.FormatAsSSN(strInstanceValue);
                                                if(strInstanceValue.Length > 0)
                                                {
                                                      strInstanceValue = "Entered";
                                                }
                                                break;                                          
                                          case("MPDOB"):
                                                if(strInstanceValue.Length > 0)
                                                {
                                                      strInstanceValue = "Entered";
                                                }
                                                break;                                          
                                          default:
                                                break;
                                    }                                                                        
                              }

                              if(strInstanceValue != "")
                              {
                                    System.Diagnostics.Debug.WriteLine("SHOULD NOT BE BLANK:  " + strInstanceValue);
                                    System.Diagnostics.Debug.WriteLine("SHOULD NOT BE BLANK:  " + Field_Name);
                                    ReplaceBookmarkWithValue(oDoc, strFullBookmarkName, strInstanceValue);                              
                              }
                        }
                        catch(Exception e)
                        {
                              switch(Field_Name)
                              {                  
                                    case("deals"):
                                          strInstanceValue = this.GetDealListForLO(myDataRow["LenderPhone"].ToString(),myDataRow["LO"].ToString(),this.FAXCOM_SPECIALONE,this.FAXCOM_SPECIALTWO);
                                          object oBookmarkName = Field_Name;
                                          Word.Range rng = oDoc.Bookmarks.Item(ref oBookmarkName).Range;
                                          rng.InsertBefore(strInstanceValue);
                                          object oApplyBorders = true;
                                          object oAutoFit = false;
                                          object oDelimiter = "=";
                                          object oColCount = 4;
                                          rng.ConvertToTable(ref oDelimiter,ref oMissing, ref oColCount,ref oMissing,ref oMissing, ref oApplyBorders, ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing, ref oAutoFit, ref oMissing, ref oMissing);
                                          Word.Table table;
                                          table = rng.Tables.Item(1);
                                          table.Rows.AllowBreakAcrossPages = -1;

                                    
                                          rng.Tables.Item(1).Rows.Item(1).Select();
                                          rng.Font.Bold = 1;
                                          rng.Tables.Item(1).Columns.Item(1).Width = 45;
                                          rng.Tables.Item(1).Columns.Item(2).Width = 135;
                                          rng.Tables.Item(1).Columns.Item(3).Width = 140;
                                          rng.Tables.Item(1).Columns.Item(4).Width = 70;

                                          break;
                                    case("message1"):
                                          if(this.FAXCOM_LETTERID == "LDL")
                                          {
                                                if(FAXCOM_LANGID==BuyersFund.GeneralFunctions.GeneralFunctions.LangTypeEnglish)                        
                                                {
                                                      tempScalarSQL = "SELECT IsNull(LetterBody,'') from tblLOLetter where (datepart(mm,IsNull([MonthToSend],0))=" + Int32.Parse(this.FAXCOM_SPECIALONE) +  ") AND (datepart(yy,IsNull([MonthToSend],0))=" + Int32.Parse(this.FAXCOM_SPECIALTWO) +  ")";
                                                }
                                                else
                                                {
                                                      tempScalarSQL = "SELECT IsNull(spanishLetterBody,'') from tblLOLetter where (datepart(mm,IsNull([MonthToSend],0))=" + Int32.Parse(this.FAXCOM_SPECIALONE) +  ") AND (datepart(yy,IsNull([MonthToSend],0))=" + Int32.Parse(this.FAXCOM_SPECIALTWO) +  ")";
                                                }                                          
                                                strInstanceValue = genFuncs.ExecScalar(tempScalarSQL,this.strPipelineDBConnection);                                          
                                                if(strInstanceValue == "")
                                                {
                                                      strInstanceValue = FAXCOM_LENDER_LETTER_DEFAULT_MESSAGE;
                                                }                                          
                                                useExceptionBlock = true;                                                                                                                                    
                                          }
                                          break;
                                    case ("PD"):
                                          tempScalarSQL = "SELECT fullname from tblDirector where directorID = " + myDataRow["PDID"];
                                          strInstanceValue = genFuncs.ExecScalar(tempScalarSQL,this.strPipelineDBConnection);                                          
                                          useExceptionBlock = true;                                                                                          
                                          break;
                                    case("zionsp"):
                                          if(myDataRow["bankName"].ToString().Length>0)
                                          {
                                                if(myDataRow["bankName"].ToString().Substring(0,4) == "Irwi")
                                                {
                                                      strInstanceValue = "";
                                                      useExceptionBlock = true;                                                
                                                }
                                          }
                                          break;
                                    case ("CityStateZip"):
                                          strInstanceValue = myDataRow["SellerCity"].ToString() + ", " + myDataRow["SellerState"].ToString() + "  " + myDataRow["SellerZip"].ToString();
                                          useExceptionBlock = true;                                                                                          
                                          break;
                                    case ("LenderInfo"):
                                          if(FAXCOM_LANGID==BuyersFund.GeneralFunctions.GeneralFunctions.LangTypeEnglish)                        
                                          {
                                                strInstanceValue = ResizeInfoToFit(myDataRow["LO"].ToString(),myDataRow["Lender"].ToString(),myDataRow["LenderPhone"].ToString(),32,44);
                                          }
                                          else
                                          {
                                                strInstanceValue = ResizeInfoToFit(myDataRow["LO"].ToString(),myDataRow["Lender"].ToString(),myDataRow["LenderPhone"].ToString(),32,41);
                                          }
                                          useExceptionBlock = true;                                                                                          
                                          break;
                                    case ("ListingRealtorInfo"):
                                          strInstanceValue = ResizeInfoToFit(myDataRow["lrRealtor"].ToString(),myDataRow["lrCompany"].ToString(),myDataRow["lrPhone"].ToString(),32,44);
                                          useExceptionBlock = true;                                                                                          
                                          break;
                                    case ("SellingRealtorInfo"):
                                          strInstanceValue = ResizeInfoToFit(myDataRow["srRealtor"].ToString(),myDataRow["srCompany"].ToString(),myDataRow["srPhone"].ToString(),32,44);
                                          useExceptionBlock = true;                                                                                          
                                          break;                                    
                                    case("suppresswelcomeletter"):
                                          tempScalarSQL = "SELECT Count(entryLenderView.EntryID) AS CountOfEntryID, entryLenderView.loName FROM entryLenderView GROUP BY entryLenderView.loName HAVING entryLenderView.loname = '" + myDataRow["loname"] + "' ORDER BY Count(entryLenderView.EntryID) DESC";
                                          numGrants = Int64.Parse(genFuncs.ExecScalar(tempScalarSQL,this.strPipelineDBConnection));
                                          if(numGrants > 1)
                                          {
                                                strInstanceValue = "";
                                                useExceptionBlock = true;                                                
                                          }
                                          break;                  
                                    case("removeifmppinfocomplete"):
                                          if(this.FAXCOM_MPPINFOCOMPLETE)
                                          {
                                                strInstanceValue = "";
                                                useExceptionBlock = true;
                                          }                                          
                                          break;                  
                                    case("completecheckbox"):
                                          object completecheckboxname = "completecheckbox";
                                          oDoc.FormFields.Item(ref completecheckboxname).CheckBox.Value = this.FAXCOM_MPPINFOCOMPLETE;                                          
                                          break;
                                    case("incompletecheckbox"):
                                          object incompletecheckboxname = "incompletecheckbox";
                                          oDoc.FormFields.Item(ref incompletecheckboxname).CheckBox.Value = !this.FAXCOM_MPPINFOCOMPLETE;                                          
                                          break;
                                    case("qualifiedcheckbox"):
                                          object qualifiedcheckboxname = "qualifiedcheckbox";
                                          oDoc.FormFields.Item(ref qualifiedcheckboxname).CheckBox.Value = this.FAXCOM_MPPVALID;
                                          break;
                                    case("notqualifiedcheckbox"):
                                          object notqualifiedcheckboxname = "notqualifiedcheckbox";
                                          oDoc.FormFields.Item(ref notqualifiedcheckboxname).CheckBox.Value = !this.FAXCOM_MPPVALID;
                                          break;
                                    default:
                                          break;
                              }
                              
                              if(useExceptionBlock)
                              {
                              
                                    ReplaceBookmarkWithValue(oDoc, Field_Name, strInstanceValue);                              
                        
                                    useExceptionBlock = false;
                              }

                              System.Diagnostics.Debug.WriteLine(e.Message);
                              System.Diagnostics.Debug.WriteLine(e.StackTrace);
                              continue;
                        }
                  }
            }
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question