Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2016, 05:14 AM
deodi deodi is offline Linking 2 dates - change one it changes the other Windows 10 Linking 2 dates - change one it changes the other Office 2010 32bit
Novice
Linking 2 dates - change one it changes the other
 
Join Date: Jun 2016
Posts: 4
deodi is on a distinguished road
Question Linking 2 dates - change one it changes the other

I have a document that I have various dates that needs to be selected by the user (will be protected so no editing on their behalf). I want to be able to choose 1 date, it should then pull through to other places. I got the "publish date" in quick parts, so I get that to work. However, I have another set of dates that should be a year later (expiry date) and this should be automatically populated by choosing the first date (publish date). As Quick Parts only have 1 date one I can't seem to create another date nor get the "fields" to work as read in other posts.



Please could you advise me on how to get the date to automatically populate by selecting the "publish date".
Reply With Quote
  #2  
Old 06-07-2016, 06:29 AM
gmayor's Avatar
gmayor gmayor is offline Linking 2 dates - change one it changes the other Windows 10 Linking 2 dates - change one it changes the other Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See http://www.gmayor.com/insert_a_date_...than_today.htm and in particular the link there to Paul's excellent work on date calculations, which you can download and copy the relevant structures to your document.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 06-07-2016, 11:57 PM
deodi deodi is offline Linking 2 dates - change one it changes the other Windows 7 32bit Linking 2 dates - change one it changes the other Office 2010 32bit
Novice
Linking 2 dates - change one it changes the other
 
Join Date: Jun 2016
Posts: 4
deodi is on a distinguished road
Default Help with code

I am still struggling to get the 'formula' to work. I want to be able to choose a date on the document (so using a drop down list) and then the expiry date should automatically populate to be a year from now less 1 day. Could you write the exact code (or explain what each line item is for) to be able to do this?

I can send you the file in order to assist?
Reply With Quote
  #4  
Old 06-08-2016, 02:37 AM
gmayor's Avatar
gmayor gmayor is offline Linking 2 dates - change one it changes the other Windows 10 Linking 2 dates - change one it changes the other Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Attach the file (or you can send it to me at supportATgmayor.com, but if you do so ensure that your forum username is in the message subject or it will be discarded).
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 06-08-2016, 04:14 AM
deodi deodi is offline Linking 2 dates - change one it changes the other Windows 7 32bit Linking 2 dates - change one it changes the other Office 2010 32bit
Novice
Linking 2 dates - change one it changes the other
 
Join Date: Jun 2016
Posts: 4
deodi is on a distinguished road
Default File uploaded

Thank you gmayor! Attached find the document.
Attached Files
File Type: docx Sworn affidavit - EME.docx (111.7 KB, 9 views)
Reply With Quote
  #6  
Old 06-08-2016, 06:04 AM
gmayor's Avatar
gmayor gmayor is offline Linking 2 dates - change one it changes the other Windows 10 Linking 2 dates - change one it changes the other Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

OK. Add the following to the ThisDocument module of the document

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    If ContentControl.Title = "Issue Date" Then
        If Not ContentControl.Range.Text = ContentControl.PlaceholderText Then
            ActiveDocument.SelectContentControlsByTitle("Expiry Date").Item(1).Range.Text = _
            DateAdd("m", 12, CDate(ContentControl.Range.Text))
        End If
    End If
End Sub
Save the document as a macro enabled template and create new documents from it. As you tab out of the first date field the second one reflects 12 added months.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 06-08-2016, 07:20 AM
deodi deodi is offline Linking 2 dates - change one it changes the other Windows 7 32bit Linking 2 dates - change one it changes the other Office 2010 32bit
Novice
Linking 2 dates - change one it changes the other
 
Join Date: Jun 2016
Posts: 4
deodi is on a distinguished road
Default Not working

I went into the document I sent you and clicked on the macros button. There was a Macros1 on the list. I clicked edit and inserted the code you provided and exited the Visual Basic. I then saved the document as a Macro Enabled Template. I then clicked on the template and chose the date on issue date, but the expiry date did not change.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking 2 dates - change one it changes the other How to change logo /dates in numerous word documents without changing each one individually? newi1 Word VBA 3 04-22-2016 07:02 PM
Autofill dates - how can I get the same date and consecutive dates? Exhale Excel 3 04-05-2016 03:11 AM
Linking 2 dates - change one it changes the other Linking dates in Headers and Footers lenoble22 Word 1 01-16-2014 12:20 PM
How to change dates automatically PaperBuster Word 5 09-24-2012 09:31 PM
How to change number format of dates ketanco Project 1 09-11-2012 02:34 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:04 PM.


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