[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Requested member of the collection does not exist

Posted on 2004-03-25
11
Medium Priority
?
1,517 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 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