For martynjpearson: SetDifferentFirstPageHeaderFooter...why do I get run error ??

martyn,

Appreciate your help here again....here is my code so far for header with logo that is to be displayed on first page only:
                  COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
                  //Creates new doc
                  Documents documents = application.GetDocuments();
                  _Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
            Selection selection(application.GetSelection());

                  Window oWin = application.GetActiveWindow();
                  Pane oPane = oWin.GetActivePane();
                  View oView = oPane.GetView();
                  oView.SetSeekView(wdSeekCurrentPageHeader);
                  //since a doc has already been opened, just find the active one
                  _Document oDocument = application.GetActiveDocument();//
                  PageSetup oPageSetup = oDocument.GetPageSetup();
                  //This initializes oPageSetup properly
                  oPageSetup.SetDifferentFirstPageHeaderFooter(1);                   
                  Selection oSel = application.GetSelection();
                  Shapes oShapes = oSel.GetInlineShapes();
                  oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
  //**********************************

This all compiles fine, but I get a run error from the following line:
oPageSetup.SetDifferentFirstPageHeaderFooter(1);

it tells me the parameter in incorrect: Why is this so...and can you help me out on this please ? I've got to get this working for next monday. Thanks.
Bruce
pigeonbrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

martynjpearsonCommented:
You could try passing VARIANT_TRUE instead of 1 - that's what I pass when I call SetDifferentFirstPageHeaderFooter().

The other thing is that when I call the function, I've got my page setup from the section, rather than the document - i.e.
   Sections sections(document.GetSections());
   Section section(sections.Item(1));
   PageSetup pageSetup(section.GetPageSetup());
   pageSetup.SetDifferentFirstPageHeaderFooter(VARIANT_TRUE);
However, I'm sure that getting the page setup from the document is still valid.

All the best
Martyn
0
pigeonbrAuthor Commented:
martyn;

Ok..things are looking up... I need some help here. I've got my footer working. My header is the way I want it for the first page, but it is showing up on all pages. Here is my code:
/*                  //**************************************
                  //Header setup with logo
                  //**************************************
                  HeaderFooter header(headers.Item(1));
                  header.SetLinkToPrevious(FALSE);
                  Range rangeHeader(header.GetRange());

                  InlineShapes shapes(rangeHeader.GetInlineShapes());
                  shapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",&varEmpty,&varEmpty,&varEmpty);
                  rangeHeader.Collapse(&varCollapse);

                  rangeHeader.InsertAfter(strHeaderText1);
                  _Font font(rangeHeader.GetFont());
                  font.SetName("Bookman Old Style Bold");
                  font.SetSize(16.0);


                  rangeHeader.InsertAfter(strHeaderText);
                  font.SetName("Bookman Old Style Bold");
                  font.SetSize(14.0);
                  font.SetUnderline(VARIANT_TRUE);

                  //Insert blank lines to start displaying the table further down so
                  //as to get just the general info on first page.
                  for(lower;lower<26;lower++)
                  {
                        selection.InsertBreak(&varLineBreak);
                        selection.Collapse(&varCollapse);
                  }
                  lower=1;

so, from the code you wrote above, I see how you setup first page from the section. I still don't understand though...how do I apply the line
pageSetup.SetDifferentFirstPageHeaderFooter(VARIANT_TRUE);
to the appropriate header code ?? My guess is to set up two headers, say header1 and header2, with the appropriate code like my sample above, but this code is using the Range object, and you code uses Sections and Section object...I'm lost here. Can you explain the theory behind using two different and using one for the first page only, and please give some sample code. Thanks.
0
martynjpearsonCommented:
It could be that you have to call SetDifferentFirstPageHeaderFooter before you do any work on the headers / footers. Alternatively, you could insert a section break after the first page - you can set the headers differently for different sections. So, after the first page, call

range.InsertBreak(wdSectionBreakNextPage);

Then, you can use the code to get the different headers and footers like this :

Sections sections(document.GetSections());
for (int nSection = 1; nSection < sections.GetCount(); nSection++)
{
   Section section(sections.Item(nSection));
   HeadersFooters headers(section.GetHeaders());
   HeaderFooter header(headers.Item(1));

  // And then you can work on your header!
}

Hope this helps
Martyn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

pigeonbrAuthor Commented:
Hi Martyn;
Ok...just got your responses to my two questions...lots of info there to sink my teeth into..:) You have answered serveral questions I was having.

One thing I would like made a little clearer is if I'm in the middle of the report, say in the second section, how can I check if I'm "after the first page" to inser tsectionbreak in this particular section since the actual number of pages depends on the unknown amount of data coming from the database CStringArray ?? I can understand the logic being applied to the first page of the whole document in my case because I will allways have the same 24 lines of client info on the first page of the document, then I can put in a section break...but in the other sections of the document, this is not the case..so how do I know when to insert the SectionBreakNextPage ?? Can i use the number of lines  ??  I guess so...but how do I go about determining the number of lines on the page? And the last page of a section will not necessarily e full...can you give me some guidelines here please martyn ?? Thanks !
0
martynjpearsonCommented:
It's difficult to tell where page breaks occur as this could vary due to differences in fonts, page setup, etc. Are you not inserting your section breaks based on your data - i.e. <some data> section break < some different data> section break < some more unrelated data> etc?
0
pigeonbrAuthor Commented:
See my otehr post as to how I set up my code please.:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.