How to create a button to print form but with restrictions

M

mcampbell

I have a form created in InfoPath. I have created a button that the users
can click to print the form. However, I wish to create an if statement that
if certain controls/fields are left blank that a window popup message screen
appears to alert the user to fill out the form completely. I have the button
working as far as just printing out the form. But I do not know how to do
the rest. I have never programmed with a script editor. I learned how to
create a button to print the document but that is as far as I can get.

The field on my form that if it is blank, the form does not need to print,
is field10.

At some point in time I will modify the button to do a print/save function
with the same stipulations, if field10 is blank then do not print or save but
to display an error message in a popup window for the user to know what is
wrong.

I may even add more fields later but for now field10 is the main field I am
concerned with.

Thanks for any help!

I am a one week old novice in using InfoPath and have never done scripting.

Here is the code from my button script:


/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/

// The following line is created by Microsoft Office InfoPath to define the
prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",
'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-30T16:49:47"');
//</namespacesDefinition>


//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL99_5::OnClick(eventObj)
{
// Write your code here
}

//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of
arguments.
//=======
function CTRL100_5::OnClick(eventObj)
{
XDocument.PrintOut(); // Write your code here
}
 
B

Ben Walters

Hody Campbell
It sounds like you may be making this more complex than it needs to be,
another option here is to simply disable the button untilt the required field
has been entered.
1: open up the properties dialog for the button and click on the "Display"
2: Click on the "Conditional Formatting" button
3: Click "Add" to add a new rule
4: from the first drop down select "Select field or group" (this will
display a dialog with your xml structure)
5: Select "Field10" anc click ok to close the dialog
6:From the second drop down select "is blank"
7: then check the "Disable this control" check box.
 
M

mcampbell

Hi Ben,

Thank you so much for your help. That was incredibly easy. It works just
like I want it to now.
 

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