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
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