Changing Views and Printing questions

R

rzwahr

I am trying to accomplish the following things in infopath and have had
problems: In a nutshell here's what I want to do:

User clicks a "Print Out View A" button I have created and that view
gets displayed as a print preview, they select the printer they want,
print it, and are still on the default view when they are done. No
switching around (at least manually) between views.

This, at least to me thus far, is WAY easier said than done. It seems
like this should be very simple though.

The way it seems this should work is, in the code, you could change the
designated print view to Print View A, print the form (using the
PrintOut method), then change the designated print view back to its'
default. I have several different print views depending on the
audience, so I have to be able to toggle between print views, based on
which view the user wants to print and which button is pressed. It
seems that this should be easy, and my first attempt was to try and
programmatically switch views, print, then switch back. I attempted to
use SwitchView to go to Print View A, issue a PrintOut, then SwitchView
back to default view. As you may guess, that bombed with the "view not
ready" error, which I still don't understand. Infopath itself switches
views with the click of a button, so why can't I make my form do it???
Anyway, the only way I can get infopath to switch views aside from
clicking the View button and selecting the desired view, is to attach a
switch view rule to a button. I'd love to know how to do all this in
pure code, but I am a rookie when it comes to this stuff. The way the
documentation talks about SwitchView, it should just switch your view
if you use it. This isn't the case, and I can't for the life of me
figure out how to get the view "ready" so I can switch to and from it.

How do I accomplish what I am trying to do - I am positive it can be
done.
 
G

Greg Collins [InfoPath MVP]

Note - the problem you are running into is that you CANNOT switch views while I view switch is in progress. This is not allowed.

Since your code is switching views, and then doing other stuff, and then attempting to switch back, this will fail because the first view switch hadn't actually completed yet.

You can however for the view to switch back once it has finished switching the first time by using the OnContextChange event handler. Set some field stating which view to switch back to--in the OnContextChange event handler, check if the field is not blank, and if not, then switch to the view specified in the field.

I'm assuming that the reason you are not using the default, built-in, print view feature is that you want to have more than one print view attached to a single edit view. If this is not the case, just specify the print view for the edit view in the View Properties dialog box.

--
Greg Collins [InfoPath MVP]
Visit http://www.InfoPathDev.com


I am trying to accomplish the following things in infopath and have had
problems: In a nutshell here's what I want to do:

User clicks a "Print Out View A" button I have created and that view
gets displayed as a print preview, they select the printer they want,
print it, and are still on the default view when they are done. No
switching around (at least manually) between views.

This, at least to me thus far, is WAY easier said than done. It seems
like this should be very simple though.

The way it seems this should work is, in the code, you could change the
designated print view to Print View A, print the form (using the
PrintOut method), then change the designated print view back to its'
default. I have several different print views depending on the
audience, so I have to be able to toggle between print views, based on
which view the user wants to print and which button is pressed. It
seems that this should be easy, and my first attempt was to try and
programmatically switch views, print, then switch back. I attempted to
use SwitchView to go to Print View A, issue a PrintOut, then SwitchView
back to default view. As you may guess, that bombed with the "view not
ready" error, which I still don't understand. Infopath itself switches
views with the click of a button, so why can't I make my form do it???
Anyway, the only way I can get infopath to switch views aside from
clicking the View button and selecting the desired view, is to attach a
switch view rule to a button. I'd love to know how to do all this in
pure code, but I am a rookie when it comes to this stuff. The way the
documentation talks about SwitchView, it should just switch your view
if you use it. This isn't the case, and I can't for the life of me
figure out how to get the view "ready" so I can switch to and from it.

How do I accomplish what I am trying to do - I am positive it can be
done.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top