Hi David,
There is not a way to do this without writing some custom script; however,
if you don't mind doing so here are sample steps:
** NOTE: I would encourage you to complete these steps completely then
migrate this to your application.
1) Create a new, blank InfoPath solution
2) From the Tools menu choose Form Options, select the Advanced tab and
make sure the Programming Language is set to VBScript.
3) Add a Date Picker control to your form (named field1) and a text box
control (named field2)
- Right-click on the Date Picker control and choose Properties
- Click the Data Validation button
- From the Events box choose OnAfterChange and then click Edit - you should
see 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. Write code here to
respond to the changes.
End Sub
- Just before the "End Sub" line of code add the following:
If eventObj.Operation = "Insert" Then
Dim objField2
Set objField2 = XDocument.DOM.selectSingleNode("//my:myFields/my:field2")
Dim intDay
Dim strDay
intDay = DatePart("w", eventObj.Site.text)
Select Case intDay
case 1
strDay = "Sunday"
case 2
strDay = "Monday"
case 3
strDay = "Tuesday"
case 4
strDay = "Wednesday"
case 5
strDay = "Thursday"
case 6
strDay = "Friday"
case 7
strDay = "Saturday"
End Select
objField2.text = strDay
End If
- The entire code 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 objField2
Set objField2 = XDocument.DOM.selectSingleNode("//my:myFields/my:field2")
Dim intDay
Dim strDay
intDay = DatePart("w", eventObj.Site.text)
Select Case intDay
case 1
strDay = "Sunday"
case 2
strDay = "Monday"
case 3
strDay = "Tuesday"
case 4
strDay = "Wednesday"
case 5
strDay = "Thursday"
case 6
strDay = "Friday"
case 7
strDay = "Saturday"
End Select
objField2.text = strDay
End If
End Sub
- Save the code and close the code editor
- Preview the form and select a date from the Date Picker - the text box
should display the correct day!
I hope this helps!
Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.