Date calculation - InfoPath Dev
in

InfoPath Dev

Date calculation

Last post 03-06-2006 09:46 AM by Rokp. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-06-2006 03:27 AM

    • Rokp
    • Top 500 Contributor
      Male
    • Joined on 03-06-2006
    • France
    • Posts 36

    Date calculation

    Hi all !!

    You will probably blame me for asking that but I got problem(s) with date calculation with Infopath.

    I understand that you must use code for any calculation date and I'm a pretty monkey with VBScript.
    I hardly search on the net and found a lot of answers ... but my code don't work at all.

    The problem :
    2 dates controlers : "PrepaDateReceptFichiers" & "PrepaDatePlanif"
    I want : "PrepaDatePlanif"= "PrepaDateReceptFichiers" + 20 days


    The solution I wrote (google wrote for me!):
    ' Ce fichier contient des fonctions relatives à la validation de données et aux événements de niveau de formulaire.
    ' Étant donné que les fonctions sont référencées dans le fichier de définition du formulaire (.xsf),
    ' il est déconseillé de modifier leur nom,
    ' ou le nom et le nombre d'arguments.

    ' La ligne suivante est créée par Microsoft Office InfoPath pour définir les préfixes
    ' de tous les espaces de noms connus dans le fichier de données XML principal.
    ' Aucune modification aux fichiers de formulaire, effectuée en dehors de InfoPath,
    ' ne sera mise à jour automatiquement.
    '<namespacesDefinition>
    XDocument.DOM.setProperty "SelectionNamespaces", "xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-06T09:58:56"""
    '</namespacesDefinition>

    '=======

    Function ISOaVB(ISODateString)
    Dim dtRetVal
    dtRetVal = Null

    If Trim(ISODateString) <> "" Then
    dtRetVal = DateSerial(Mid(ISODateString, 1, 4), _
    Mid(ISODateString, 6, 2), Mid(ISODateString, 9, 2))
    End If

    ISOaVB = dtRetVal
    End Function

    '=======

    Function VBaISO(ISODateString)
    '?????
    End Function

    '=======

    Sub CTRL19_13_OnClick(eventObj)

    Dim ISOdebut
    Dim ISOfin
    Dim DATEdebut
    Dim DATEfin

    'Récupère la date "début" au format ISO
    ISOdebut = XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDateReceptFichiers")

    'Convertit la date ISO en date VBScript
    DATEdebut = ISOaVB(ISOdebut)

    'Ajoute 20 jours
    DATEfin = Dateadd("d", 20, ISOdebut)

    'Convertit la date VBScript en date ISO
    ISOfin = VBaISO(DATEfin)

    'Renvoie la date "fin" au format ISO
    XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDateReceptDocs") = ISOfin

    End Sub

    Sorry, this code contain a lot of french words.


    Where the first problem is :
    this line :
    ISOdebut = XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDateReceptFichiers")
    make the code bug.

    Infopath tell me that there is an 'execution error', 'non-define variable' ... something like that.
    InfoPath 2003 SP2
  • 03-06-2006 03:40 AM In reply to

    HI Rokp,

    Try out this link
    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1711

    Hope this will help You.
  • 03-06-2006 06:49 AM In reply to

    • Rokp
    • Top 500 Contributor
      Male
    • Joined on 03-06-2006
    • France
    • Posts 36
    Okay, thanks !!

    Well I rewrote something more simple :

    Sub CTRL20_13_OnClick(eventObj)

    Dim ISOdebut
    Dim ISOfin
    Dim DATEdebut
    Dim DATEfin


    Set ISOdebut = XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDateReceptFichiers")

    DATEdebut = CDate(ISOdebut.text)

    DATEfin = Dateadd("d", 20, DATEdebut)

    ISOfin = Mid(DATEfin,7,4) & "-" & Mid(DATEfin,4,2) & "-" &Mid(DATEfin,1,2)

    XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDatePlanif").text = ISOfin

    End Sub




    The only thing that doesn't work corectly is the last line.
    Indeed, the following error does occur :
    L'erreur suivante s'est produite :

    « #PCDATA » se trouve dans un contenu nul : <http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-09T18:14:58}PrepaDatePlanif>.

    Fichier :script.vbs
    Ligne:38


    That's crazy, I'm about to find the answer...
    InfoPath 2003 SP2
  • 03-06-2006 07:39 AM In reply to

    • Rokp
    • Top 500 Contributor
      Male
    • Joined on 03-06-2006
    • France
    • Posts 36
    I made another try with a blank page and it works perfectly.

    It appears that this line :

    XDocument.DOM.setProperty "SelectionNamespaces", "xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-06T09:58:56"""

    ...is very important.

    It contains : 2006-03-06T09:58:56

    I don't know why it makes the formular I made bugging, but I must find.

    An idea ??
    InfoPath 2003 SP2
  • 03-06-2006 09:46 AM In reply to

    • Rokp
    • Top 500 Contributor
      Male
    • Joined on 03-06-2006
    • France
    • Posts 36
    I got it !
    The Date Control PrepaDatePlanif must be formated as "text" and not "date"



    Sub CTRL20_13_OnClick(eventObj)

    Dim ISOdebut
    Dim ISOfin
    Dim DATEdebut
    Dim DATEfin


    Set ISOdebut = XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDateReceptFichiers")

    DATEdebut = CDate(ISOdebut.text)

    DATEfin = Dateadd("d", 20, DATEdebut)

    XDocument.DOM.selectSingleNode("/my:mesChamps/my:GroupeInformations/my:DatesPrepa/my:PrepaDatePlanif").text = DATEfin

    End Sub
    InfoPath 2003 SP2
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.