Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2018, 12:06 PM
joshuaran joshuaran is offline Selecting a Date in Date Picker and Having it change dates throughout Windows 10 Selecting a Date in Date Picker and Having it change dates throughout Office 2010 32bit
Novice
Selecting a Date in Date Picker and Having it change dates throughout
 
Join Date: Mar 2018
Posts: 1
joshuaran is on a distinguished road
Default Selecting a Date in Date Picker and Having it change dates throughout


I am trying to insert a date picker in a word 2010 document that has several tables in it. I want to be able to select the date picker at the top of the page and have it change dates at the top of each table by a selected number of days. I have scoured through all the tutorials and cant find an answer. I can do this easily in Adobe Acrobat however, the document doesnt expand to fit extra text if needed, without reworking the entire document.
Reply With Quote
  #2  
Old 03-14-2018, 08:52 PM
Charles Kenyon Charles Kenyon is offline Selecting a Date in Date Picker and Having it change dates throughout Windows 10 Selecting a Date in Date Picker and Having it change dates throughout Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,083
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

This is far from a trivial task.
You can either use the Publish Date Document Property Content Control (which you can customize) and repeat it or you can bookmark the control and refer to its results in complex fields.

Here is a copy of one such field, just to give you an idea of the complexity.
{ QUOTE "{ SET " Delay" "14" }
{
SET "DaysInMonth" { IF { CreateDate \@ "MM" } <> 2
{
= ROUND(30.575*
{ CreateDate \@ "MM" },0)-
ROUND(30.575*
{ = { CreateDate \@ "MM" } -1 },0) }
{
IF { = MOD( { CreateDate \@"yy" } , 4 ) } > 0 "28" "29" } } }
{
SET "NextMonth" { IF { CreateDate \@ "MM" } = 12 "1/97"
"
{ = { CreateDate \@ "MM"} + 1 }/97 } }
{
IF { = { REF "Delay" } + { CreateDate \@ "dd" } } <= {REF"DaysInMonth"}
{
CreateDate \@ "MMMM { = { REF "Delay" } + { CreateDate \@ "dd" } }, yyyy"}{ QUOTE { NextMonth \@ "MMMM"
}
{
=
{ REF "Delay" } + { CreateDate \@ "dd" } - { REF"DaysInMonth" } },
{
IF { CreateDate \@ "MM" } <> 12 { CreateDate \@ "yyyy" }
{
CreateDate \@ "{ = 1 + { CreateDate \@ "yyyy" } \# "xxxx" }" } } } }" }


You would be using a copy of the Publish Date control or a REF field to the bookmark instead of CreateDate in your fields.

Luckily, Paul Edstein has compiled a tutorial that is a Word document with a compendium of such fields that you can copy and change to fit. Be sure to read the introductory material. You can find it here: https://www.msofficeforums.com/word/...-tutorial.html

The reason for using the Publish Date Document Property control instead of your own is explained here: Repeating Data Using Document Properties Content Controls and Other Mapped Content Controls
Reply With Quote
  #3  
Old 03-14-2018, 09:24 PM
macropod's Avatar
macropod macropod is offline Selecting a Date in Date Picker and Having it change dates throughout Windows 7 64bit Selecting a Date in Date Picker and Having it change dates throughout Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The field code solution proposed by Charles probably isn't suitable in this case, as you're using a date picker content control - not a formfield - and you'd require a ContentControlOnExit macro to trigger the field updates. And, since you'll require such a macro, you'd probably do better to avoid the field coding altogether and instead use a ContentControlOnExit macro in the 'ThisDocument' code module of the document or its template, coded along the lines of:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim Dt As Date, StrDt As String
With CCtrl
  If .Title <> "StartDate" Then Exit Sub
  If .ShowingPlaceholderText = True Then
    ActiveDocument.SelectContentControlsByTitle("DateOffset1")(1).Range.Text = "Pending"
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(1).Range.Text = "Pending"
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(2).Range.Text = "Pending"
    ActiveDocument.SelectContentControlsByTitle("DateOffset3")(1).Range.Text = "Pending"
  Else
    StrDt = .Range.Text
    If IsDate(StrDt) Then
      Dt = CDate(StrDt)
    Else
      Dt = CDate(Split(StrDt, (Split(StrDt, " ")(0)))(1))
    End If
    ActiveDocument.SelectContentControlsByTitle("DateOffset1")(1).Range.Text = Format(Dt + 7, .DateDisplayFormat)
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(1).Range.Text = Format(Dt + 14, .DateDisplayFormat)
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(2).Range.Text = Format(Dt + 14, .DateDisplayFormat)
    ActiveDocument.SelectContentControlsByTitle("DateOffset3")(1).Range.Text = Format(Dt + 21, .DateDisplayFormat)
  End If
End With
Application.ScreenUpdating = True
End Sub
The above code presupposes your date picker content control is titled 'StartDate' and you have three child plain text content controls titled 'DateOffset1', 'DateOffset2', and 'DateOffset3', respectively, with two instances on the 'DateOffset2' content control.

See attached demo.

If you wanted to have offsets that might fall on weekends, but the calculated date should fall on the previous Friday or following Monday, you could use something like:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim Dt As Date, StrDt As String, i As Long
With CCtrl
  If .Title <> "StartDate" Then Exit Sub
  If .ShowingPlaceholderText = True Then
    ActiveDocument.SelectContentControlsByTitle("DateOffset1")(1).Range.Text = "Pending"
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(1).Range.Text = "Pending"
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(2).Range.Text = "Pending"
    ActiveDocument.SelectContentControlsByTitle("DateOffset3")(1).Range.Text = "Pending"
  Else
    StrDt = .Range.Text
    If IsDate(StrDt) Then
      Dt = CDate(StrDt)
    Else
      Dt = CDate(Split(StrDt, (Split(StrDt, " ")(0)))(1))
    End If
    Select Case Dt Mod 7
      Case 0: i = -1 'Saturday to Friday
      Case 1: i = 1 'Sunday to Monday
      Case Else: i = 0
    End Select
    ActiveDocument.SelectContentControlsByTitle("DateOffset1")(1).Range.Text = Format(Dt + 9 + i, .DateDisplayFormat)
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(1).Range.Text = Format(Dt + 14, .DateDisplayFormat)
    ActiveDocument.SelectContentControlsByTitle("DateOffset2")(2).Range.Text = Format(Dt + 14, .DateDisplayFormat)
    ActiveDocument.SelectContentControlsByTitle("DateOffset3")(1).Range.Text = Format(Dt + 23 + i, .DateDisplayFormat)
  End If
End With
Application.ScreenUpdating = True
End Sub
The above example provides for the calculated date to become Friday if it otherwise falls on a Saturday, and to become Monday if it otherwise falls on a Sunday.

To make both dates Friday, change:
Case 1: i = 1 'Sunday to Monday
to:
Case 1: i = -2 'Sunday to Friday

To make both dates Monday, change:
Case 0: i = -1 'Saturday to Friday
to:
Case 0: i = 2 'Saturday to Monday
Attached Files
File Type: docm Content Control Date Calculations.docm (40.3 KB, 23 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
word 2010;

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting a Date in Date Picker and Having it change dates throughout Date picker content control to always show current date. lucky16 Word VBA 2 07-01-2016 01:14 PM
Possible to link a date picker to another date picker? tubbz Word 0 05-07-2014 01:23 PM
Default dates for a Date Picker BoringDavid Word VBA 2 09-11-2013 01:42 AM
Selecting a Date in Date Picker and Having it change dates throughout Date Picker Andy2011 Word VBA 4 11-24-2012 10:07 PM
Date picker trintukaz Excel 0 12-30-2011 12:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft