How to close a form with a changed event? - InfoPath Dev
in

InfoPath Dev

How to close a form with a changed event?

Last post 08-28-2008 08:23 AM by davidlozzi. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-16-2008 01:41 AM

    • ddregs
    • Not Ranked
    • Joined on 07-16-2008
    • Posts 2

    How to close a form with a changed event?

    Hi all,

    I wrote some code behind a combo-box, in the changed event, where I check the existance of a saved xml and load it if found. I'd like to close the current window , to leave only the found file open.

    I tried submitting the active window and in the submit code I used the Application.ActiveWindow.Close(true). But it still doesn't work giving the usual

    System.Runtime.InteropServices.COMException
    Invalid context for OM call.
    at Microsoft.Office.Interop.InfoPath.SemiTrust.Window.Close(Boolean fForce)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.WindowObjectWrapper.Close(Boolean fForce)
       at Microsoft.Office.InfoPath.Internal.WindowHost.Close(Boolean force)
       at PRil.FormCode.FormEvents_Submit(Object sender, SubmitEventArgs e)

    I know I cannot execute the Window.Close method at the changed method, but this time I am triggering the submit (via code) and expected it to be run.

    Any suggestions? Thanks in advance for your help.
     

  • 07-17-2008 07:01 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: How to close a form with a changed event?

    Hello,

    You have to use the below code for close the form.

    e.ReturnStatus = false

     

    Otherwise you can close the form from taskpane.

     

  • 07-21-2008 12:37 AM In reply to

    • ddregs
    • Not Ranked
    • Joined on 07-16-2008
    • Posts 2

    Re: How to close a form with a changed event?

    Thanks Shiva for the tip.

    Unfortunately I couldn't find any ReturnStatus properties for the object e, neither in the changed event nor in the submit event.

    Could you please advice me where to insert that code line?

    Thanks
     

  • 07-22-2008 02:38 AM In reply to

    Re: How to close a form with a changed event?

    Hope this works for you this.Close();
    Thanks & Regards,
    Srikrushna Patro.
  • 08-01-2008 07:40 AM In reply to

    Re: How to close a form with a changed event?

    My form is web based and this.close is not available in VSTA as its compatibility is set to IPFS. any other method to close the form? Thanks  

    Filed under:
  • 08-28-2008 08:23 AM In reply to

    • davidlozzi
    • Not Ranked
    • Joined on 08-28-2008
    • Wilmington, MA
    • Posts 1

    Re: How to close a form with a changed event?

    So, I'm having the same need, and I think i found a work around. The save button that submits my form has code and a rule as well that closes the form. So the form code runs first, then the rules are applied. So on click, the code runs, does some logic then submits it, then the rules run and closes the form. 

    The issue with this is that if there is an error on the submit, the form still closes and now i'm out of luck. What I did to remedy this was add a hidden field called closeForm, and set the condition of the rule in the save button to check if the closeForm field is not blank, then close the form. By default, this text box will be blank. I set a value in this text box after the submit completes successfully, so the form should only close upon a successful submittal.

    I then handle the error and let the end user know. Works pretty darn well!

     

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.