How hard can it be to close infopath

S

Stanley

Hi,
i am trying to close infopath in manage code but get these errors:
- object or reference not set
- security error
- The form was not found in the Xdocuments collection
- Invalid context for OM Call
- etc etc...

I've tried these codes:
- thisApplication.XDocuments.Close(thisXDocument);
- thisApplication.Quit(false);
- thisApplication.ActiveWindow.Close(false);
- thisApplication.ActiveWindow.XDocument.View.Window.Close(false)
- etc etc... every possible combination

And none of them won't close the form. Why is it so hard to just close a
simple form? Can somebody help me out? I've looked throughout the whole group
already.

I have some old forms where i use js script and there it works fine, but
when using .NET code it doesn't work anymore. It goes for lots of other
things by the way.

Regards,

Stanley
 
F

Franck Dauché

Hi Stanley,

Can you drop a New button on your form and use the following code:
thisApplication.ActiveWindow.Close(true);

Does it help?

Where are you calling your code from? This might be your issue. For
example if you call it from the OnLoad event, you would experience issues
such as the one that you describe.

Regards,

Franck Dauché
 
S

Stanley

Franck,
I am calling the quit() from the onload event indeed. When i do it through a
button it works. Your correct.
What i am trying to achieve is when opening the form i do some validation,
if the validation turns out negative, the form has to be closed. Is this
(even) possible?

Thnx,
Stanley
 
S

Stanley

I noticed that lots of code doesn't work in the onload event. I would like to
try switching view in the onload event instead of closing the form. But that
than gives an object reference error.
 
F

Franck Dauché

Hi Stanley,

OnLoad, use:
thisXDocument.ViewInfos["YouViewName"].IsDefault = true;

Switching to a different View at first is a good technique. If the user
credentials are OK, switch back to your main View, otherwise, close InfoPath.

Hope that it helps.

Regards,

Franck Dauché
 

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