<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40364.aspx</link><pubDate>Mon, 06 Apr 2009 15:31:42 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40364</guid><dc:creator>b.harrison</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40364.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40364</wfw:commentRss><description>&lt;p&gt;Greg, Jimmy, thanks for your input!&lt;/p&gt;
&lt;p&gt;I did find a workaround for it.&amp;nbsp; If my custom validation fails, I set a field value in the newly opened form (Form B) to &amp;quot;Abort&amp;quot;.&amp;nbsp; From the opening form (A), I can check this field value and if it is &amp;quot;Abort&amp;quot; I can close Form B from there using one of the methods above.&lt;/p&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40362.aspx</link><pubDate>Mon, 06 Apr 2009 15:15:25 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40362</guid><dc:creator>Jimmy</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40362.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40362</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/infopathdev/images/icon-quote.gif"&gt; &lt;strong&gt;b.harrison:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;I just remembered that, although we are developing on 2007, we are using the backward compatibility option with 2003 (most of our users only have 2003 on their PCs).&amp;nbsp; This might be why it does not work? 
&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;Sure is :-)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;nbsp;&lt;font size="2"&gt;thisXDocument.View.Window.Close(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;font size="2"&gt;should do the trick.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Edit:&amp;nbsp; I see you already tried that.&amp;nbsp; As Greg pointed out, you can only close the form on certain events. Perhaps you can find a workaround to meet that criterion?&lt;/p&gt;&lt;/font&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40361.aspx</link><pubDate>Mon, 06 Apr 2009 15:14:54 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40361</guid><dc:creator>Greg Collins</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40361.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40361</wfw:commentRss><description>&lt;p&gt;If you read through the documentation you discover:&lt;/p&gt;
&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&amp;quot;the &lt;b class="bterm"&gt;Close&lt;/b&gt; method can only be used with the &lt;u&gt;OnSubmitRequest&lt;/u&gt; and &lt;u&gt;OnClick&lt;/u&gt; event handlers. &lt;u&gt;If used with any other type of event handler, it will return an error&lt;/u&gt;.&amp;quot;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;I hope that helps.&lt;/p&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40360.aspx</link><pubDate>Mon, 06 Apr 2009 15:03:14 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40360</guid><dc:creator>b.harrison</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40360.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40360</wfw:commentRss><description>&lt;p&gt;Thanks, Hilary, but I am getting a build error when I try that.&lt;/p&gt;
&lt;p&gt;When I type just &amp;quot;this.&amp;quot; in visual studio, the intellisense brings up the list of all of the methods and members of the current class.&amp;nbsp; Is there something I need to do to make the this refer to the current document and not the current class?&lt;/p&gt;
&lt;p&gt;I just remembered that, although we are developing on 2007, we are using the backward compatibility option with 2003 (most of our users only have 2003 on their PCs).&amp;nbsp; This might be why it does not work?&lt;/p&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40359.aspx</link><pubDate>Mon, 06 Apr 2009 14:48:09 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40359</guid><dc:creator>Hilary Stoupa</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40359.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40359</wfw:commentRss><description>&lt;p&gt;this.Close(); will close the form. &lt;/p&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40358.aspx</link><pubDate>Mon, 06 Apr 2009 14:38:58 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40358</guid><dc:creator>b.harrison</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40358.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40358</wfw:commentRss><description>&lt;p&gt;2007 and C#&lt;/p&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40356.aspx</link><pubDate>Mon, 06 Apr 2009 14:32:52 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40356</guid><dc:creator>Hilary Stoupa</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40356.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40356</wfw:commentRss><description>&lt;p&gt;What version of InfoPath are you using? 2003 or 2007? C# for your code? &lt;/p&gt;</description></item><item><title>Re: Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40295.aspx</link><pubDate>Fri, 03 Apr 2009 15:06:37 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40295</guid><dc:creator>b.harrison</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40295.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40295</wfw:commentRss><description>&lt;p&gt;Well, I just tried making a new viewbut when I try to switch to it in OnAfterChange I get the error: &amp;quot;&amp;quot;InfoPath cannot execute any view-related object model calls. The view is not ready.&amp;quot;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I think I am stuck.&lt;/p&gt;</description></item><item><title>Another post about closing a form via code</title><link>https://www.infopathdev.com:443/forums/thread/40294.aspx</link><pubDate>Fri, 03 Apr 2009 15:00:49 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:40294</guid><dc:creator>b.harrison</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/40294.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=40294</wfw:commentRss><description>&lt;p&gt;I have two forms.&amp;nbsp; Form A has a link that opens Form B.&amp;nbsp; When B is opened it verifies some various user input, which is done in Form B&amp;#39;s OnAfterChange() event code.&amp;nbsp; If the verification fails I want to close Form B.&amp;nbsp; I have tried all of the following:&lt;/p&gt;
&lt;p&gt;thisApplication.XDocuments.Close(1);&lt;br /&gt;thisApplication.XDocuments.Close(thisApplication.XDocuments[1]);&lt;br /&gt;thisApplication.XDocuments.Close(thisApplication.XDocuments[1].URI);&lt;br /&gt;thisApplication.XDocuments.Close(e.XDocument);&lt;br /&gt;thisApplication.XDocuments.Close(e.XDocument.URI);&lt;br /&gt;thisXDocument.View.Window.Close(true);&lt;br /&gt;thisXDocument.View.Window.Close(false);&lt;br /&gt;thisApplication.ActiveWindow.Close(true);&lt;br /&gt;thisApplication.ActiveWindow.Close(false);&lt;/p&gt;
&lt;p&gt;None of them work.&amp;nbsp; I get &amp;quot;Invalid context for OM call.&amp;quot; every time.&lt;/p&gt;
&lt;p&gt;I looked at the posts &lt;a href="http://www.infopathdev.com/forums/p/6165/22767.aspx#22767"&gt;http://www.infopathdev.com/forums/p/6165/22767.aspx#22767&lt;/a&gt;&amp;nbsp;and &lt;a href="http://www.infopathdev.com/forums/p/3543/14114.aspx#14114"&gt;http://www.infopathdev.com/forums/p/3543/14114.aspx#14114&lt;/a&gt;&amp;nbsp;but neither provided a solution for this specific problem.&amp;nbsp; 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)?&amp;nbsp; If I need to, I can just make a new view with an error&amp;nbsp;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.&amp;nbsp; Both forms are running in Full Trust, if that matters.&lt;/p&gt;
&lt;p&gt;Any help or ideas are appreciated!&lt;/p&gt;</description></item></channel></rss>