Date Calculations

G

Gailc

Hi,

I have designed a form that employees need to complete to request time off.

I have 2 date pickers. Date Picker A (Effective Date) and Date Picker B
(Return Date). Below these date pickers I would like to autopopulate a text
box with the total number of days required off. Return Date minus Effective
Date.

Unfortunately I am not a programmer but I can follow thorough instruction....

Thanks
Gailc
 
G

Gailc

Thanks Scott. I already found this BLOG - but unfortunately I have no coding
knowledge - I need step by step instructions?

Thanks
 
G

Gailc

--
Gailc


Gailc said:
Thanks Scott. I already found this BLOG - but unfortunately I have no coding
knowledge - I need step by step instructions?

If you could provide me with details - like the details you provided in the
Question "Date Calculations for a non-programmer" - that would be terrific.>
 
S

Scott L. Heim [MSFT]

Hi,

Please accept my apologies for the delay as I was unexpectedly out of the
office for a few days.

Here are steps to a basic sample - with the following caveats:

1) This is using VBScript and not JScript
2) There is no real error handling here - so you will need to add
additional functionality, such as: confirmation that one date is greater
than or equal to the other, both fields are not empty, etc.

- Create a new, blank form
- Add the following controls and names:
- Date Picker, EffectiveDate
- Date Picker, ReturnDate
- Text box, txtDiff

- Right-click on ReturnDate and select Properties
- Click the Data Validation button
- In the Events box, choose OnAfterChange and then click Edit
- You should now see basically the following:

Sub msoxd_my_ReturnDate_OnAfterChange(eventObj)
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

- Place your cursor in the space just before the words "End Sub" and paste
in the following code:

'When you add/edit text in a control, we go through a "delete" process to
remove any existing text
'and then an "Insert" process to enter what you just selected or typed -
we only want this code to execute
'during the "Insert" process - as such, we need to test for the correct
operation
If eventObj.Operation = "Insert" Then
Dim objEffDate
Dim objRetDate
Dim objDiff

'Get references to the XML nodes that correspond to our controls
Set objEffDate =
XDocument.DOM.selectSingleNode("//my:myFields/my:EffectiveDate")
Set objRetDate =
XDocument.DOM.selectSingleNode("//my:myFields/my:ReturnDate")
Set objDiff = XDocument.DOM.selectSingleNode("//my:myFields/my:txtDiff")

'If the EffectiveDate field is not an empty string (in other words a date
was selected)
'then compare this (the ReturnDate) to the EffectiveDate field.
If objEffDate.text <> "" Then
objDiff.text = DateDiff("d", objEffDate.text, objRetDate.text)
End If

'Clean up
Set objEffDate = Nothing
Set objRetDate = Nothing
Set objDiff = Nothing
End If

- Preview the form and test

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

Gailc

Hi Scott,

Thanks so much for responding. I have successfully added the code to the
ReturnDate events but when I test the code by selecting an effective date
and a return date no data diff between dates) is automatically entered into
the txtdiff text box.

Maybe there is a step that I am missing?

Thanks in advance.
 
G

Gailc

Hi Scott,

One other thing, when I close the form I am told there is a "code error" but
there is no option for viewing the error....

Thanks
 
D

Dave Harris

Did you manage to get this sorted? I am in the same situation as you. Not
a programmer!
 

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