weeknumber from Date()

G

Ger

Hi all,

On a form I have a "Datepicker". I want to know the weeknumber of the date
the user clicked. Is there an easy reference ?

gr. Ger.
 
S

Scott L. Heim [MSFT]

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.
 
G

Ger

Hi Scott,

Indeed your solution worked well, but I had to redesign the form, followed
your instructions, but, whatever I do, I got an error : Object required
objDate. I did exactly what you instructed and exactly the same as the last
time, but no luck.

What can be wrong ??

Ger.
 
G

Ger

First I thought it was, because in the redesign I use a dataconnection to a
database, but then I tried it in a new, blank form and I got the same error:
Object objDate required.... This object has been declared !!!
So I suppose something is wrong with the Set object-statement, but what ?
I am astonished and like to learn what is matter here ....

Ger.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top