PDA

View Full Version : [SOLVED:] Dependent Date pickers in word



laxman106
09-08-2015, 08:46 AM
Hello,

My document contains two date pickers. Is it possible that selecting a date in first date picker would change the date in second date picker to a date that is 3 days after the date selected in first one. For example, if I select 09/05/2015 in first date picker, then second date picker would change to 09/08/2015. Can you please help on how to achieve this.
Thank you!

gmaxey
09-08-2015, 04:40 PM
Assuming they are contentcontrol datepickers titled "Date" and "Date Advanced"


Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oCC As ContentControl
Select Case ContentControl.Title
Case "Date"
Set oCC = ActiveDocument.SelectContentControlsByTitle("Date Advanced").Item(1)
With oCC
.LockContents = False
If IsDate(ContentControl.Range.Text) Then
.Range.Text = DateAdd("d", 3, CDate(ContentControl.Range.Text))
Else
.Range.Text = vbNullString
End If
End With
End Select
End Sub

laxman106
09-09-2015, 07:31 AM
WOW! now i have dependent dates in document. THANK YOU VERY MUCH! Really Appreciate your help.

gmaxey
09-09-2015, 01:33 PM
Oops. You probable want to set .LockContents = True immediately after the End If line.

You're welcome.

jmglastetter
07-01-2016, 01:34 PM
Hi Greg,

Thank you for the answer above, as it was the same question I had!

After struggling to accomplish this, I've narrowed down my issue. My first datepicker, titled "date", uses the date style "dddd, MMMM d". Seems the addition of the "dddd" is causing the break.

Is there a way to focus the attention on the date "d", when the day of the week "dddd", is also present?

Best Regards,
Jeremy

gmaxey
07-01-2016, 07:28 PM
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oCC As ContentControl
Select Case ContentControl.Title
Case "Date"
ContentControl.DateDisplayFormat = "MMM/dd/yyyy"
Set oCC = ActiveDocument.SelectContentControlsByTitle("Date Advanced").Item(1)
With oCC
.LockContents = False
If IsDate(ContentControl.Range.Text) Then
.Range.Text = DateAdd("d", 3, CDate(ContentControl.Range.Text))
Else
.Range.Text = vbNullString
End If
.LockContents = True
End With
ContentControl.DateDisplayFormat = "dddd, MMM dd, yyyy"
End Select
End Sub