Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2012, 07:06 AM
jillapass jillapass is offline Retrieving content control value Windows 7 32bit Retrieving content control value Office 2007
Novice
Retrieving content control value
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default Retrieving content control value

I have a word form where I use a content control date picker for the user to enter 3 dates
I need to use the value of one of these dates to make up the filename when the document is saved.



My problem is that I cannot figure out how to retrieve the value from the content control.

Any help greatly recieved.

The other fields are all bookmarks taken from a userform, but I couldn't find a way in the userform to allow the user to pick a date from a pop up calendar, this would be the other option to what I am trying to do.

Thanks
Reply With Quote
  #2  
Old 05-23-2012, 09:29 AM
jjfreedman jjfreedman is offline Retrieving content control value Windows 7 64bit Retrieving content control value Office 2010 32bit
Advanced Beginner
 
Join Date: May 2012
Location: https://jay-freedman.info
Posts: 39
jjfreedman is on a distinguished road
Default

If you want a date picker on a userform, first you need to get and register the file mscal.ocx. For that, visit http://www.fontstuff.com/vba/vbatut07.htm. Step 2 on that page also explains how to put the control on the toolbox and how to use it. The drawback here is that you need to have the ocx on every computer that will use the form, and it's no longer common.

If you stick with the content control, then you can get its value with the expression ActiveDocument.ContentControls(1).Range.Text -- just substitute the correct index in the parentheses to get the particular control you need. Alternatively, put a unique Tag value in that control, and use the ActiveDocument.SelectContentControlsByTag method to get the correct one. (That method returns a collection of content controls, but if your tag is unique then you know the collection contains only one control, so you can use the index 1 to get the control.)
Reply With Quote
  #3  
Old 05-24-2012, 12:55 AM
jillapass jillapass is offline Retrieving content control value Windows 7 32bit Retrieving content control value Office 2007
Novice
Retrieving content control value
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default

Thank you very much for the help, worked great, except

The date they enter shows in the format 24/05/2012 whereas I need to use it in the file name as 'yyyy mmdd' with the space in the middle.

The bit of code I have is very simple.


Dim FBdate
FBdate = ActiveDocument.ContentControls(3).Range.Text


Do I need to specify FBdate as a date, and how do I then get the bits of it to get year, month, day or is there a function that does this.

As you can probably tell I am a novice at this.

Thanks
Reply With Quote
  #4  
Old 05-24-2012, 05:04 AM
jjfreedman jjfreedman is offline Retrieving content control value Windows 7 64bit Retrieving content control value Office 2010 32bit
Advanced Beginner
 
Join Date: May 2012
Location: https://jay-freedman.info
Posts: 39
jjfreedman is on a distinguished road
Default

The simplest way to change the arrangement of the dates is to use the Format function. I'd recommend that you look up the Help topic about this function to see all the things it can do (easy: after you type Format in the macro window, put the cursor inside the word and press F1). For this specific case, what you need is

Dim FBdate As String
FBdate = ActiveDocument.ContentControls(3).Range.Text
FBDate = Format(FBDate, "yyyy mmdd")

At that point FBDate will have the proper form, and you can use it to make a file name.

If you need to do other things with the date, such as adding days or months to it, investigate the data type named Date and the function CDate that converts strings to Date objects.
Reply With Quote
  #5  
Old 05-24-2012, 05:07 AM
jillapass jillapass is offline Retrieving content control value Windows 7 32bit Retrieving content control value Office 2007
Novice
Retrieving content control value
 
Join Date: Dec 2011
Posts: 26
jillapass is on a distinguished road
Default

thankyou for your help.
I must admit I am finding it very difficult to find good information on the commands available.
I have a book, but that seems to be based on 2003 not 2007 and just getting a list of the commands available seems to be quite a task in itself.

Anyway thanks again and on with the project.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving content control value Move to next content control cksm4 Word VBA 13 07-02-2019 07:48 PM
retrieving notes in outlook that were deleted donbmar Outlook 0 05-21-2011 12:18 PM
Retrieving content control value content control Word 2007 TessaLee Word 1 03-11-2011 12:51 AM
Package for CD with links to Windows media player content and Flash Shockwave content hectorh PowerPoint 4 10-15-2009 12:22 PM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:21 AM.


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