Hi,
If you are/can use VBScript then this would be relatively easy:
- Create a new, blank InfoPath form
- Insure the form is set to use VBScript
- Add a Date Picker control (named txtDate) and a text box (named txtWeek)
- Right-click on the txtDate field, choose Properties, click the Data
Validation button, select OnAfterChange from the Events box and click the
Edit button
- You should see basically the following:
Sub msoxd_my_field1_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.
End Sub
- Add the following code just before the End Sub line:
If eventObj.Operation = "Insert" Then
Dim objDate
Dim objWeek
Set objDate = XDocument.DOM.selectSingleNode("//my:myFields/my:txtDate")
Set objWeek = XDocument.DOM.selectSingleNode("//my:myFields/my:txtWeek")
objWeek.text = DatePart("ww", objDate.text)
End If
- The entire procedure should now look like this:
Sub msoxd_my_field1_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
Dim objDate
Dim objWeek
Set objDate = XDocument.DOM.selectSingleNode("//my:myFields/my:txtDate")
Set objWeek = XDocument.DOM.selectSingleNode("//my:myFields/my:txtWeek")
objWeek.text = DatePart("ww", objDate.text)
End If
End Sub
- Save and close the Script Editor
- Preview the form and select a date from the Date Picker control - you
should get the week number in txtWeek!
I hope this helps.
Best regards,
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.