Error switching views on open

K

KWenstrup

I'm trying to open one form from another, based on a selection made in the
first form. The code I've found that opens this correctly seems to be:

XDocument newDoc = thisApplication.XDocuments.NewFromSolution(...Template
Name)

IXMLDOMNode newQueryNode = newDealDoc.DOM.selectSingleNode("//s0:queryId");
if(newQueryNode != null)
{
newDealQueryNode.text = dealIdNode.text;
}
IXMLDOMNode newDealOpenMode =
newDealDoc.DOM.selectSingleNode("//my:OpenMode");
if(newDealOpenMode != null)
{
newDealOpenMode.text = "Edit";
}
 
K

KWenstrup

Sorry, I posted before I was done. Here's the complete question:

I'm trying to open one form from another - code below. I need the second
form to open and query the web service based on the selection in the first
form. That will cause the view in the second form to switch based on the
data retrieved.

To do that, I create new second form and then set the ID into it and an
"OpenMode" node, for which I've coded the AfterChange event to do my querying
(and other stuff). The problem is that after the query, it tries to change
the view based on the state of the data. I get the following error:

Infopath cannot execute any view-related object model calls. The view
is not ready.

How can I get it to switch views at this point. I think maybe I need to
change the way I open completely - but can't find any examples.

Thanks: - Ken

The psuedocode;

XDocument newDoc = thisApplication.XDocuments.NewFromSolution(...Template)

IXMLDOMNode newQueryNode = newDoc.DOM.selectSingleNode("//s0:queryId");
newQueryNode.text = idToOpen;

IXMLDOMNode openModeNode = newDoc.DOM.selectSingleNode("//s0:eek:penMode)"
openModeNode = "Edit"
 
M

Michelle

Ken,

Have you tried using the Open Rules in the Form Options dialog (From
the Tools menu) to set up a rule that switches view based on a value
in a node when the form is opened?

Michelle
 
S

Steve van Dongen [MSFT]

KWenstrup said:
I'm trying to open one form from another - code below. I need the second
form to open and query the web service based on the selection in the first
form. That will cause the view in the second form to switch based on the
data retrieved.

To do that, I create new second form and then set the ID into it and an
"OpenMode" node, for which I've coded the AfterChange event to do my querying
(and other stuff). The problem is that after the query, it tries to change
the view based on the state of the data. I get the following error:

Infopath cannot execute any view-related object model calls. The view
is not ready.

HOWTO: Programmatically Change the Default View
http://support.microsoft.com/default.aspx?scid=kb;en-us;826997

Regards,
Steve
 
K

KWenstrup

Thank you both for these answers. Unfortunately, the problem is that at open
time, I don't quite know the view yet. I open a blank form, set the
variables which cause the service to be queried, and then based on the result
of the query, switch views:

XDocument newDoc = thisApplication.XDocuments.NewFromSolution(...Template
Name)
IXMLDOMNode newQueryNode = newDealDoc.DOM.selectSingleNode("//s0:queryId");
newDealQueryNode.text = dealIdNode.text;
IXMLDOMNode newDealOpenMode =
newDealDoc.DOM.selectSingleNode("//my:OpenMode");
newDealOpenMode.text = "Edit";

In the AfterChange of this last element, I know to query the database for
this element and switch views based on the result. So at open time, the form
is still blank. So maybe the question is - how do I initialize the form
before doing the NewFromTemplate call, so that this information is available
before opening.

Thanks:
- Ken
 
N

Nick

"System.Runtime.InteropServices.COMException (0x8004305B): InfoPath cannot
execute any view-related object model calls. The view is not ready.\r\n at
Microsoft.Office.Interop.InfoPath.SemiTrust.View.SwitchView(String
bstrName)\r\n at
Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.SwitchView(String
bstrName)\r\n at
Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.SwitchView(String
bstrName)\r\n at
Infopath_Managed_Task_Pane.Infopath_Managed_Task_Pane.BTN_SelectProject_OnClick(DocActionEvent
e) in d:\\data\\stratus\\infopath forms\\formcode.cs:line 496"

Im having the same problem except, I know the view name prior to runtime.
It seems that only one view is causing this problem. All other views I can
switch to programmatially without problem... is there a way to detect if a
view is ready? Are there any things to check for in the specific view that
may cause this problem?

Thanks,
Nick
 
N

Nick

OK, i just solved my own problem, so hopefully this will help out anyone else..

I was trying to switch views in an event handler, were the object passed in
is the DocActionEvent. This conveniently has XDocument property. I made the
call from here instead of the global reference to the XDocument, and problem
solved.
 
Top