Since you've bound your form to a database, I'm guessing that you're using
the calculation within a repeating section or table? The example on my
website uses just two date pickers that are not repeating. If you want to
extend the sample to a repeating table, you'll have to retrieve the date
pickers and total fields for each row in a repeating group and perform the
calculation for each row.
---
S.Y.M. Wong-A-Ton
:
Hi,
I have implemented the VBScript
(
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm)
in a New Blank Form, and it's works. But when I use a New Form with a SQL
Server Data Base connection, the difference between dates not works, I don't
have any results.
Someone can help?
Thanks in advance,
Paulo Pina
:
I've updated the solution posted on my website to include an entire
step-by-step example of how this can be done. See
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
---
S.Y.M. Wong-A-Ton
:
Thank you for responding again.
The error was added as a reply to post by me but for some reason is not in
this message chain. However, this was when I was placing it in the default
value which I know is the wrong place.
I have in the form as you suggested - 2 date pickers and an whole number
(integer) field to return the number of days. I have now entered the code in
the event handlers for both date pickers. The calculating field returns
nothing.
If I enter a formula in the calculating field I get 'NaN'.
I am sorry to be of trouble with this but have no coding background what so
ever and a demanding client who says the form MUST be able to do this
Thanks and regards,
Al
:
You didn't include the error, but in any case, you mustn't add the code as
the formula for the Default Value, but you need to add an event handler for a
button or a field.
I'm not sure how your form is layout or when the difference should be
calculated, but if you have two date pickers and a third field showing the
difference, you need to add an OnAfterChange event handler to each date
picker and then copy and paste the code in those event handlers.
To add an event handler for the date pickers:
- Double-click on the field
- Click on the [Data Validation...] button
- Select the OnAfterChange event
- Click on the [Edit...] button which will add the event handler for you and
take you to the Microsoft Script Editor
You can also take a look at
http://enterprise-solutions.swits.net/infopath/adding-time-calculating-differences.htm for instructions on how to do this.
---
S.Y.M. Wong-A-Ton
:
Thanks S.Y.M. Wong-A-Ton.
I have implemented the VBScript in the form successfully (i.e. the first
section of code), however when I add the other code to the field I receive
the error listed below. I am adding this to the 'Default Value' formula. I
am assuming this is the 'event handler' you are referring to. If not, where
is this section?
Thanks and best regards,
Alison
:
Unfortunately, you will have to use code for the calculation between dates,
since the calculation using rules and filters is too complicated, if not
impossible. I've managed to do many tricks with rules, but reached my limit
with dates.
Try taking a look at the date and time solutions on my website:
http://enterprise-solutions.swits.net/infopath/solutions.htm#datetime and in
particular this one:
http://enterprise-solutions.swits.net/infopath/datediff-vbscript-infopath.htm
Hope this helps.
---
S.Y.M. Wong-A-Ton
:
Hi,
I am no coding wizard....technical person I am so I need some help with a
field calculation.
I have seen the useful information on how to calculate the hours between a
start time and an end time and was wondering if there is a similar method for
calculating the number of days between a start date and an end date?
If anyone can shed some light on this for me, I'd be more than grateful.
Al...