I have two forms. Form A has a link that opens Form B. When B is opened it verifies some various user input, which is done in Form B's OnAfterChange() event code. If the verification fails I want to close Form B. I have tried all of the following:
thisApplication.XDocuments.Close(1);
thisApplication.XDocuments.Close(thisApplication.XDocuments[1]);
thisApplication.XDocuments.Close(thisApplication.XDocuments[1].URI);
thisApplication.XDocuments.Close(e.XDocument);
thisApplication.XDocuments.Close(e.XDocument.URI);
thisXDocument.View.Window.Close(true);
thisXDocument.View.Window.Close(false);
thisApplication.ActiveWindow.Close(true);
thisApplication.ActiveWindow.Close(false);
None of them work. I get "Invalid context for OM call." every time.
I looked at the posts http://www.infopathdev.com/forums/p/6165/22767.aspx#22767 and http://www.infopathdev.com/forums/p/3543/14114.aspx#14114 but neither provided a solution for this specific problem. Is it just not possible to close a form from its own event function (I have also tried closing a form in the OnSubmit event code and had the same results)? If I need to, I can just make a new view with an error message and a button that will close the form, and switch to this view if the validation fails, but I would really like to be able to do it all in code. Both forms are running in Full Trust, if that matters.
Any help or ideas are appreciated!