SwitchView Error

B

bbryenton

I am trying to open another form, actually there are 12 different
forms, from an existing form. The new forms have between 7 - 10
views, and depending on the data entered in the first form, a
different view should appear.

I enter the code

public void OpenNew(string target, string view, bool close)
{
XmlForm f =
this.Application.XmlForms.NewFromFormTemplate(target);
if (close)
this.Close();
try
{
if (f.CurrentView.ViewInfo.Name != view)
{
f.ViewInfos.SwitchView(view);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "ACS
Infopath Internal");
}
}

The error I get all of the time is:

COM Exception
InfoPath cannot execute any view-related object model calls. The view
is not ready.

System.Runtime.InteropServices.COMException was unhandled by user code
Message="InfoPath cannot execute any view-related object model
calls. The view is not ready."
Source="InfoPath"
ErrorCode=-2147209125
StackTrace:
at
Microsoft.Office.Interop.InfoPath.SemiTrust.View.SwitchView(String
bstrName)
at
Microsoft.Office.Interop.InfoPath.SemiTrust.ViewObjectWrapper.SwitchView(String
bstrName)
at
Microsoft.Office.InfoPath.Internal.ViewInfoCollectionHost.SwitchView(String
name)
at ACS2.FormCode.OpenNew(String target, String view, Boolean
close)
at ACS2.FormCode.TestView_Clicked(Object sender,
ClickedEventArgs e)
at
Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent
pEvent)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent
pEvent)

Any help is appreciated

Thanks, Bob
 
F

Frank Mueller \(MSFT\)

Hi Bob,

Do you always close the current form before switching the view in the new
form? I am wondering if that could cause problems.
Also when you see the error is the new form fully loaded? The error message
seems to indicate that this is not the case.

Thanks,
Frank
 
B

Bob

Hi Frank, thanks for the response. I have tried closing it and not
closing it. The code I posted is on a test project of two very small
blank forms with two views each. The other form looks like it is
loaded as I have tried putting messages in the load events. I even
went as far as to add Log4Net to see if I could figgure out what was
happening. I am truely stumped.

Bob
 

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