Solved

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

Posted on 2003-11-24
9
350 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:pigeonbr
  • 3
  • 3
9 Comments
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9816637
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
 

Author Comment

by:pigeonbr
ID: 9842916
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
 
LVL 8

Accepted Solution

by:
martynjpearson earned 125 total points
ID: 9848703
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
Technology Partners: 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!

 

Author Comment

by:pigeonbr
ID: 9851805
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
 
LVL 8

Expert Comment

by:martynjpearson
ID: 9866051
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
 

Author Comment

by:pigeonbr
ID: 9874914
See my otehr post as to how I set up my code please.:)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

680 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