Hi Scott,
this is the code i use, please take a look al it, Jhon
' 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/2005-07-25T20:21:43"""
'</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.
' This function is associated with the following field or group (XPath):
/my:myFields/my:txtStartTime
' Note: Information in this comment is not updated after the function
handler is created.
'=======
Sub msoxd_my_txtStartTime_OnAfterChange(eventObj)
' Write code here to restore the global state.
If eventObj.IsUndoRedo Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If
' A field change has occurred and the DOM is writable. Write code here to
respond to the changes.
If eventObj.Operation = "Insert" Then
' A field change has occurred and the DOM is writable. Write code here to
respond to the changes.
Dim objEndTime
Set objEndTime =XDocument.DOM.selectSingleNode("//my:myFields/my:txtEndTime")
If objEndTime.text <> "" Then
CalcTime cdate(objEndTime.text) - cdate(eventObj.Site.text)
End If
End If
End Sub
'=======
' 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.
' This function is associated with the following field or group (XPath):
/my:myFields/my:txtEndTime
' Note: Information in this comment is not updated after the function
handler is created.
'=======
Sub msoxd_my_txtEndTime_OnAfterChange(eventObj)
' Write code here to restore the global state.
If eventObj.IsUndoRedo Then
' An undo or redo operation has occurred and the DOM is read-only.
Exit Sub
End If
' A field change has occurred and the DOM is writable. Write code here to
respond to the changes.
If eventObj.Operation = "Insert" Then
' A field change has occurred and the DOM is writable. Write code here to
respond to the changes.
Dim objStartTime
Set objStartTime =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtStartTime")
If objStartTime.text <> "" Then
CalcTime cdate(eventObj.Site.text) - cdate(objStartTime.text)
End If
End If
'Below all of this code, add the following function:
Function CalcTime(interval)
Dim objStartTime
Dim objEndTime
Dim objElapsedTime
'Get a reference to each field
Set objStartTime =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtStartTime")
Set objEndTime = XDocument.DOM.selectSingleNode("//my:myFields/my:txtEndTime")
Set objElapsedTime =
XDocument.DOM.selectSingleNode("//my:myFields/my:txtElapsedTime")
Dim totalhours, totalminutes
Dim hours, Minutes
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
If Len(minutes) = 1 Then Minutes = "0" & Minutes
CalcTime = hours & ":" & Minutes
objElapsedTime.text = CalcTime
End Function CalcTime
End Sub