Submitting to a Specific Data Connection via Code

D

Deb

Thanks to the many good people on this forum, I have the following code I
typically put behind a Submit button on my forms which checks for required
fields having values, then submits and closes InfoPath. If I use Rules to
submit, there is no way to tell InfoPath to close itself.

So, what I now need is the ability to specify what Data Connection to submit
to. Can that be done within the XDocument.Submit() line below?

{
if (XDocument.Errors.Count > 0)
{XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).") ;
return;
}
try
{
XDocument.Submit()
Application.ActiveWindow.Close(true);
}
catch(e)
{
XDocument.UI.Alert(e.description);
}
 
S

S.Y.M. Wong-A-Ton

It is best to use

XDocument.DataAdapters["Main connection"].Submit();

where "Main connection" is the name of the data connection used to submit
your form.
 
D

Deb

Thank you, S.Y.M.!

After posting this I discovered something I didn't know previously. The
Submit Rules that you set up from the Tools...Submitting Forms section for
the entire form control everything. The XDocument.Submit() on each button
apparently pushes up to those centralized rules. This makes it easy for me.
That way I don't have to worry about specifying the data connection on each
object. I can use field values and rules at the global location. Boy, wish
I had known that sooner. ;-)




S.Y.M. Wong-A-Ton said:
It is best to use

XDocument.DataAdapters["Main connection"].Submit();

where "Main connection" is the name of the data connection used to submit
your form.
---
S.Y.M. Wong-A-Ton


Deb said:
Thanks to the many good people on this forum, I have the following code I
typically put behind a Submit button on my forms which checks for required
fields having values, then submits and closes InfoPath. If I use Rules to
submit, there is no way to tell InfoPath to close itself.

So, what I now need is the ability to specify what Data Connection to submit
to. Can that be done within the XDocument.Submit() line below?

{
if (XDocument.Errors.Count > 0)
{XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).") ;
return;
}
try
{
XDocument.Submit()
Application.ActiveWindow.Close(true);
}
catch(e)
{
XDocument.UI.Alert(e.description);
}
 
S

S.Y.M. Wong-A-Ton

You're welcome! Thanks for posting the tip; other may benefit from it.
---
S.Y.M. Wong-A-Ton


Deb said:
Thank you, S.Y.M.!

After posting this I discovered something I didn't know previously. The
Submit Rules that you set up from the Tools...Submitting Forms section for
the entire form control everything. The XDocument.Submit() on each button
apparently pushes up to those centralized rules. This makes it easy for me.
That way I don't have to worry about specifying the data connection on each
object. I can use field values and rules at the global location. Boy, wish
I had known that sooner. ;-)




S.Y.M. Wong-A-Ton said:
It is best to use

XDocument.DataAdapters["Main connection"].Submit();

where "Main connection" is the name of the data connection used to submit
your form.
---
S.Y.M. Wong-A-Ton


Deb said:
Thanks to the many good people on this forum, I have the following code I
typically put behind a Submit button on my forms which checks for required
fields having values, then submits and closes InfoPath. If I use Rules to
submit, there is no way to tell InfoPath to close itself.

So, what I now need is the ability to specify what Data Connection to submit
to. Can that be done within the XDocument.Submit() line below?

{
if (XDocument.Errors.Count > 0)
{XDocument.UI.Alert("Required information is missing as indicated by the red
asterisk(s).") ;
return;
}
try
{
XDocument.Submit()
Application.ActiveWindow.Close(true);
}
catch(e)
{
XDocument.UI.Alert(e.description);
}
 

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