Solved

Requested member of the collection does not exist

Posted on 2004-03-25
11
1,490 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:knowlton
  • 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: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:knowlton
ID: 10682960
Is Item(int Index)    0 based    or 1 based?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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: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: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: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 500 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: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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on link 14 46
converto datetime always changes format 9 35
C# LINQ ForEach() question 6 17
Calculate number of nights between two dates 5 17
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now