Need help with particular printing requirement

P

Philip Colmer

I've been working on a purchase request form. This form has two print
views - one for the originator and one for the Finance department. I've put
together a Sub that gets called when the user clicks on a Print button:

Public Sub CTRL98_5_OnClick(ByVal e As DocActionEvent)
If e.XDocument.Errors.Count <> 0 Then
MsgBox("Please ensure that all fields have been completed
properly. The form currently contains some errors.",
MsgBoxStyle.Exclamation, "Print request")
Else
' Preserve the current view
Dim current_view As String = e.XDocument.View.Name
' Switch to the accounts version of the print view & print
it
Try
' Switch to the accounts version of the print view &
print it
e.XDocument.View.SwitchView("PrintAccountsVersion")
e.XDocument.PrintOut()
Catch ex As Exception
MsgBox("Error while trying to print accounts' copy: " &
ex.ToString, MsgBoxStyle.Information, "Error while printing")
End Try
Try
' Switch to the originators version of the print view &
print it
e.XDocument.View.SwitchView("PrintOriginatorsVersion")
e.XDocument.PrintOut()
Catch ex As Exception
MsgBox("Error while trying to print originator's copy: "
& ex.ToString, MsgBoxStyle.Information, "Error while printing")
End Try
Try
' Now restore the previous view
e.XDocument.View.SwitchView(current_view)
Catch ex As Exception
MsgBox("Error while trying to restore original view: " &
ex.ToString, MsgBoxStyle.Information, "Error while printing")
End Try
End If
End Sub

The idea is that when the user click on the button, the printing will only
occur if all of the fields have been completed successfully. Each of the
print views would then be printed.

The problem I've got is that it appears that InfoPath doesn't allow or
cannot cope with multiple calls to SwitchView. The attempt to switch to the
second print view, and then to the original view, fail with a "view is not
ready" error.

Since "PrintOut" only works against the current view, it would seem that
even if I only wanted to print ONE print view, I still can't do what I want,
since I would be able to switch to the print view, print it, then revert
back to the original view.

Can anyone suggest a way to implement this?

Thanks.

--Philip
 
A

AaLoK43

I dont have much exp. in Infopath..I have started recently so plz
excuse me if I'm wrong.

I feel the view has not been created at the point of OnLoad so no
instance is created..

Try to place your code i.e. PrintOut() in OnSwitchView event handler.

Hope it works...:)
 
P

Philip Colmer

AaLoK43 said:
I dont have much exp. in Infopath..I have started recently so plz
excuse me if I'm wrong.

I feel the view has not been created at the point of OnLoad so no
instance is created..

Try to place your code i.e. PrintOut() in OnSwitchView event handler.

Hope it works...:)

Thank you for the suggestion, but that won't help. You aren't supposed to
call PrintOut from the OnSwitchView event handler because that has problems
of its own.

One thing that did occur to me is that the view that is used for printing is
an attribute of the "editing" view. So ... it occurs to me that if I can
change that attribute, I can:

a) Call PrintOut() to print the already defined print view.
b) Change the value of the attribute to the other print view.
c) Call PrintOut() again.

That way, I don't actually have to call SwitchView, but I'm not sure if I
can overwrite attributes through managed code. Does anyone know if that is
possible?

--Philip
 
P

Philip Colmer

Philip Colmer said:
One thing that did occur to me is that the view that is used for printing
is an attribute of the "editing" view. So ... it occurs to me that if I
can change that attribute, I can:

a) Call PrintOut() to print the already defined print view.
b) Change the value of the attribute to the other print view.
c) Call PrintOut() again.

That way, I don't actually have to call SwitchView, but I'm not sure if I
can overwrite attributes through managed code. Does anyone know if that is
possible?

Turns out that it doesn't seem to be possible. I found the attribute that
defines the print view for a given view, but the DOM is read-only so I can't
change the value of the attribute.

So, I've had now choice but to merge the two print views into one with a
page break between them. This has had the downside of needing to remove the
page numbers.

Maybe InfoPath 12 will provide us with more control over printing ...

--Philip
 

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