Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / March 2008

Tip: Looking for answers? Try searching our database.

Retrieving day of the week from date picker

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
david - 15 Aug 2005 02:43 GMT
Is there a way to retrieve the day of the week (eg. 'Wednesday', 'Friday',
etc) from a date picker control box?

If the date selected is the 15th of August, 2005, and the day is Monday, I'd
like to be able to retrieve 'Monday' and display it in an expression box.

Is there an easy way to do this?

Thanks
Scott L. Heim [MSFT] - 15 Aug 2005 14:32 GMT
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
RDB - 16 Apr 2007 15:28 GMT
I don't know if Scott is still around; hopefully someone can provide a little
guidance on this issue.  The script Scott posted below works fine on a basic
form.  However, if I create a form that submits to a database, I can't
validate calendar entries using the script below.  I receive the following
error message when any date is selected in the date picker:

"A run-time error has occurred.
Do you want to debug?

The following error occurred:

Object required: 'objField2'
File:script.vbs
Line:56"

I've been able to duplicate this error in a completely new form as
well...and I'm able to get this script to work in a basic database where
there is no database connection.  Any ideas?

> Hi David,
>
[quoted text clipped - 108 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights
stout27 - 17 Mar 2008 15:55 GMT
Is there a way to do this in Infopath 2007?

Thanks.

>Hi David,
>
[quoted text clipped - 108 lines]
>
>This posting is provided "AS IS" with no warranties, and confers no rights

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.