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.