Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40" - InfoPath Dev
in

InfoPath Dev

Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

Last post 01-11-2013 07:56 PM by varam4u. 24 replies.
Page 1 of 2 (25 items) 1 2 Next >
Sort Posts: Previous Next
  • 05-30-2012 06:30 AM

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Hello All,

     My first post here. I am very happy to see a forum for the very challenging InfoPath. I know Excel, Word and PowerPoint very well. In addition to PowerPoint, InfoPath is proving to be as challenging also.

     Here's my question...

     

    I have created a timesheet with 2 rows of several text boxes. Row 1 contains "Hours Worked" text boxes for each day with a "Total Hours Worked" text box at the end. Row 2 contains "Absence" text boxes for each day with an " Total Absence" text box at the end. The sum of both boxes should always total "40".

    What I want is an error to show up when the user attempts to publish/send the timesheet if the sum of the "Total Hours Worked" & "Total Absence" boxes do not equal "40".

     How do I do this?

     

    Thanks much

    Filed under: , ,
  • 05-30-2012 10:25 AM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    You could use custom validation for this - add validation to the Total Hours Worked and the Total Absences fields that is triggered if the two added together is not equal to 40.

    You could also just use rules on your submit - have the condition be if the two fields don't equal 40 to display a message box (filler only - we don't have message boxes in browser forms) and then don't run any of the remaining rules (which would actually submit your form) if the conditions of that rule are met....

    Hilary Stoupa

  • 05-30-2012 10:33 AM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Thanks for the reply.

     I actually figured that is what I needed to do but I didn't/don't know how to say "if these two boxes don't equal 40 trigger an error", in the rules/error boxes. Would you be able to tell me step-by-step how to do this?

     I am using InfoPath 2007.

     

    Thanks

  • 05-30-2012 10:47 AM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Well, the formula will depend on the XPath to the fields.

    What I usually do when I need to create a condition that is sort of outside the scope of the drop downs in the condition builder is leave the first drop down to whatever it is defaulted to, and the second it's default (usually, the first would be the field you are setting the validation on, and the second is "is equal to"). Then, for the third drop down, select Use a formula.

    In the formula editor, you can use the field picker to select your two fields, and put at " + " sign between them.

    Then, once you click okay and are back in the conditional formatting, change the first drop down to the "The expression". Now you'll have a larger text area, and it will look something like:

    . = my:myFields/my:XPathToOneField + my:myFields/my:XPathToMyOtherField

    You can change the "." to 40, and wrap the whole thing in a not:

    not(40 = my:myFields/my:XPathToOneField + my:myFields/my:XPathToMyOtherField)

    Or, use !=

    40 != my:myFields/my:XPathToOneField + my:myFields/my:XPathToMyOtherField

    Does that make sense?

     

    Hilary Stoupa

  • 05-30-2012 11:07 AM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Oh boy, I wish I could just borrow your InfoPath mind and this would be so much easier lol.

    I already have formulas in both of my two fields: "Hours_Total" and "Absence_Total" which adds the fields in Monday through Friday up.

    What do I do if I am already using formulas in these two fields?

     Thanks so much for the help here.

  • 05-30-2012 11:19 AM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Are these actual fields with formulas? You can just use the fields themselves - the expression will only consider their current values (it doesn't care how the values get there). Does that make sense?

    If they are expression boxes, you can use the formulas:

    40 != sum(XPath to Absence fields) + sum(XPath to Hours fields)

    Hilary Stoupa

  • 05-30-2012 11:25 AM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Hmmm,

     Ok, here is what I have in the "Text Box Properties"/"Value"/"Insert Formula" text box of my "Hours_Total" field...

    Hours_Monday + Hours_Tuesday + Hours_Wednesday + Hours_Thursday + Hours_Friday + Hours_Saturday + Hours_Sunday

     Would I put the expression after all that? If yes, do I hit "Enter" on my keyboard after "Sunday"?

     Thanks

  • 05-30-2012 11:40 AM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    What I am trying to say is that you can just use the Hours_Total field. I'm attaching a sample. Save the file locally. Right click the saved file. Select Design, this will open the template in design mode.

    Hilary Stoupa

  • 05-30-2012 11:56 AM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    WWoWW,

     I don't know how anyone is supposed to figure that out without the help of people like yourself. I am going to absorb this a bit and see how I do with it. I will do my best to try and keep you posted the second I am either successfull or have another newbie question. There's is NO way I would've been able to do that on my own. I have another question that I posted to my IT department who can't figure out the answer to that maybe you know. I'll put it into another post in the next 5 minutes.

     Thanks again for all your help Hilary :)

  • 05-30-2012 12:06 PM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    You bet - if you have trouble implementing this in your form, you can always attach your form under the Options tab and I can give you a hand.

    Hilary Stoupa

  • 05-30-2012 12:52 PM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    Hilary,

     I tried copying your code (changing "Field 7" to "Hours_Total" and "Field 8" to "Absence_Total" and I'm sure it's my fault, but it didn't work.

    One quick question though...

    In field 7 you refer to field 8 and field 8. In field 8 you refer to field 7 and field 8. Is this the way it should be? See below...

    For the expressions on Field 7, you have...

     0 != xdMath:Nz(.) + xdMath:Nz(../my:field8)

    and

    40 != xdMath:Nz(.) + xdMath:Nz(../my:field8)

     

    For the expressions on Field 8, you have...

    40 != xdMath:Nz(.) + xdMath:Nz(../my:field7)

     0 != xdMath:Nz(.) + xdMath:Nz(../my:field8)

     

    Sorry about the large font, I tried to reduce them but there doesn't seem to be a way.

     

    Thanks

  • 05-30-2012 01:06 PM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    The formula on field8 is a victim of a sloppy copy / paste error. :-)

    Should be:

    0 != xdMath:Nz(.) + xdMath:Nz(../my:field7)

    as you suspected...

    So much will have to do with the correct XPath for your fields. Can you right click each of them in the data source task pane, and select Copy XPath and paste the XPath into a reply?

    Hilary Stoupa

  • 05-31-2012 06:57 AM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

     (Sorry for the delay)

    Sure, here you go...(paths below are from right-clicking on "Absence_Total" and clicking on "Copy XPath". Same with Absence_Total.

    Hours_Total XPath =       /my:myFields/my:Hours/my:Total_Hours/my:Hours_Total

    Absence_Total XPath =     /my:myFields/my:Absence/my:Absence_Total

     

    Ok, so I was able to Publish a blank timesheet, which I what I desire. But then, I intentionally left all the Hours and Absent Hours blank so that it wouldn't total 40 and it still let me email the form to myself. Once I received the form, there was a red box around the "Hours_Total" and "Absence_Total" boxes and hovering over them brought up the message I created "Total is not 40 hours".

     My goal is to not even allow the form to email unless the total is 40 hours. Can this be done?

    Thanks

  • 05-31-2012 07:30 AM In reply to

    • duugg
    • Not Ranked
    • Joined on 05-29-2012
    • Posts 13

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    One more note:

    Even when "Hours_Total" and "Absence_Total" combined total DOES equal 40, they still have a red border around each of them with the same error. I'm sure it's something I'm doing I just don't know what it is.

     Thanks

  • 05-31-2012 07:43 AM In reply to

    Re: Data Validation: Do not allow form to publish/send if the sum of two text boxes do not equal "40"

    What is the expression you are currently using for your validation?

    Hilary Stoupa

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