Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2017, 08:47 AM
corriganc corriganc is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Novice
Want to use the DateAdd function to type text at a location in word document, using date from CC
 
Join Date: Jul 2017
Location: United Kingdom
Posts: 6
corriganc is on a distinguished road
Angry Want to use the DateAdd function to type text at a location in word document, using date from CC

I am trying to get a macro (VBA) to type the date in 6 or 12 months time.


I have managed to get it to work from today's date but that is unfortunately not the date that we need.

We need it to add 6 or 12 months onto a date which is specified by the user in a DatePicker Content Control.

The way this will be done is the user will either click "6th Months" or "12 Months" (MacroButtons) and this will run the corresponding macro (6 months will add 6 months onto the date specified).

I then also need the macro to delete the other MacroButton, so that only the clicked button remains.

I really need this urgently, and any help that anyone can provide will be greatly appreciated.

Please disregard all VBA code within this doc, as the majority no longer works due to me keep having to change various parts.

Please someone help me!!!

Thankyou.

[I'm only 15 and I'm really really new to this!]
Attached Files
File Type: docx template-broken-upload.docx (29.3 KB, 9 views)
File Type: docx template-workingish-upload.docx (30.6 KB, 8 views)
Reply With Quote
  #2  
Old 07-28-2017, 10:17 PM
gmayor's Avatar
gmayor gmayor is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

There is no code in your documents as docx format does not support code.

You can use the content control exit event to perform calculations, something like the attached, but you need to name at least the relevant fields (and better still all of them) and you need to have a date value that you can add to. Your Date of Manufacture field shows only the year. You cannot add months to a year. So in the attached I have added a last examination field for the purpose of demonstration.

The code adds six months of a year to the value of that date (or nothing if the field is showing the prompt).
Attached Files
File Type: docm template-fixed-upload.docm (38.0 KB, 14 views)
__________________
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 07-29-2017, 03:55 AM
corriganc corriganc is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Novice
Want to use the DateAdd function to type text at a location in word document, using date from CC
 
Join Date: Jul 2017
Location: United Kingdom
Posts: 6
corriganc is on a distinguished road
Smile Genius!

Quote:
Originally Posted by gmayor View Post
There is no code in your documents as docx format does not support code.

You can use the content control exit event to perform calculations, something like the attached, but you need to name at least the relevant fields (and better still all of them) and you need to have a date value that you can add to. Your Date of Manufacture field shows only the year. You cannot add months to a year. So in the attached I have added a last examination field for the purpose of demonstration.

The code adds six months of a year to the value of that date (or nothing if the field is showing the prompt).
You are a genius!
I have no idea how you managed to do this, and I am very grateful. Could you just do me one more huge favour please?

Where you added the "Last Examination" line into the document, in order for it to calculate the "Next Examination" value, it actually needs to come from the date field which is in the black textbox at the bottom of the page.

I have included an image with this reply so that it makes more sense. If you could look into this for me please, I would be most grateful - I am going to try to work it out by myself in the meantime, but I fear that I will be just as useless this time as the first time!

Thankyou in advance, and for what you have done already.

Callum
Attached Images
File Type: jpg Template-Ammends.JPG (73.1 KB, 22 views)
Attached Files
File Type: docm template-fixed-upload.docm (39.5 KB, 9 views)
Reply With Quote
  #4  
Old 07-29-2017, 07:04 AM
gmayor's Avatar
gmayor gmayor is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

Just delete the paragraph that you have scribbled out. The other field already has the required name and that will be used by the macro.
__________________
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 07-29-2017, 07:47 AM
corriganc corriganc is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Novice
Want to use the DateAdd function to type text at a location in word document, using date from CC
 
Join Date: Jul 2017
Location: United Kingdom
Posts: 6
corriganc is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
Just delete the paragraph that you have scribbled out. The other field already has the required name and that will be used by the macro.
I'll try it now, and will update you accordingly!
Reply With Quote
  #6  
Old 07-29-2017, 10:39 AM
corriganc corriganc is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Novice
Want to use the DateAdd function to type text at a location in word document, using date from CC
 
Join Date: Jul 2017
Location: United Kingdom
Posts: 6
corriganc is on a distinguished road
Smile

Quote:
Originally Posted by gmayor View Post
Just delete the paragraph that you have scribbled out. The other field already has the required name and that will be used by the macro.
I've just tested out your most recent suggestion, and it worked!
There is only one issue with the document - since the user is more likely to enter the "LastExamination" text after they have entered the "Frequency" text how would I go about modifying the code to calculate the date after the "LastExamination" field is entered, rather than after the "Frequency" field. An even better solution would be to have it calculate/modify the "NextExamination" date after the "Freqency" or the "LastExamination" field is entered. Basically, that would mean that the "NextExamination" field would be populated correctly regardless of which order the user fills in the document; because at the moment, if the "Frequency" field is filled in before the "LastExamination" field (which is now at the bottom) the document displays a VBA error [Type Mismatch] - I can forsee this being an issue since trying to explain to the users that they need to fill in the bottom before the top will blow their minds!

Any help that you could provide would be greatly appreciated; I did try to work it out myself, but the code is far too complex for me - my status on this site describes me perfectly - "Novice"!

Kind Regards,
Callum
Reply With Quote
  #7  
Old 07-29-2017, 09:02 PM
gmayor's Avatar
gmayor gmayor is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

This is becoming a major exercise

You can process any field on exit or on entry by use of event macros. I noticed that you used a date field - don't as this updates each time the document is opened, rendering it useless. You have also used a field for the examiner. This doesn't provide any facility to change the examiner. Use either a text content control or a dropdown control listing all the examiners.

The form should be a template from which you create new documents - attached.
Attached Files
File Type: dotm template-fixed-upload.dotm (47.0 KB, 21 views)
__________________
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
  #8  
Old 08-08-2017, 07:34 AM
corriganc corriganc is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Novice
Want to use the DateAdd function to type text at a location in word document, using date from CC
 
Join Date: Jul 2017
Location: United Kingdom
Posts: 6
corriganc is on a distinguished road
Thumbs up

Quote:
Originally Posted by gmayor View Post
This is becoming a major exercise

You can process any field on exit or on entry by use of event macros. I noticed that you used a date field - don't as this updates each time the document is opened, rendering it useless. You have also used a field for the examiner. This doesn't provide any facility to change the examiner. Use either a text content control or a dropdown control listing all the examiners.

The form should be a template from which you create new documents - attached.
Hi again,
Thanks for that, is there any chance you could send me the non-template version please, as I need to add the company's logo and information back to it, and when I add it to your template, and then save that as a new template, the coding is lost!

Kind Regards,
Callum
Reply With Quote
  #9  
Old 08-08-2017, 09:36 PM
gmayor's Avatar
gmayor gmayor is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

Copy the company logo to the template then simply save the template (or don't forget to save as a macro enabled template) then the code should be retained.
__________________
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
  #10  
Old 08-09-2017, 05:52 AM
corriganc corriganc is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Novice
Want to use the DateAdd function to type text at a location in word document, using date from CC
 
Join Date: Jul 2017
Location: United Kingdom
Posts: 6
corriganc is on a distinguished road
Thumbs down

Quote:
Originally Posted by gmayor View Post
Copy the company logo to the template then simply save the template (or don't forget to save as a macro enabled template) then the code should be retained.
I've just tried that and for some reason, the code is being lost.
I am downloading your most recent file, adding the logo, then saving said file as a MacroEnabled Template...
Reply With Quote
  #11  
Old 08-09-2017, 08:07 PM
gmayor's Avatar
gmayor gmayor is offline Want to use the DateAdd function to type text at a location in word document, using date from CC Windows 10 Want to use the DateAdd function to type text at a location in word document, using date from CC Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

Send me the modified template to supportATgmayor.com (change AT to @) with your forum username in the message subject so I can see what you have (or have not) done.
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Want to use the DateAdd function to type text at a location in word document, using date from CC How to have the location (path) of the Word document on the title bar? Jamal NUMAN Word 24 09-06-2017 12:18 PM
Returning text, date, time, location from one Excel sheet to another dave57 Excel 17 06-15-2017 10:45 AM
Want to use the DateAdd function to type text at a location in word document, using date from CC Word type document auto fill in Sircooks Excel 5 05-14-2016 05:01 AM
Want to use the DateAdd function to type text at a location in word document, using date from CC Why do pages 10-24 disappear when I type in more text on page 2 or paste new text into the document? RET Word 1 05-02-2016 07:28 PM
Date Function in word? aligahk06 Word 1 04-21-2010 06:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:19 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