Microsoft Office Forums word 2003 date picker

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2010, 09:17 AM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default word 2003 date picker

Hello,



I wanted to know if it is possible to add a date picker in a Microsoft word 2003 document. I am trying to create a word 2003 document for users to select and enter specific fields and select the required date using the date picker.

I would really appreciate any help.

Thanks !
Reply With Quote
  #2  
Old 09-27-2010, 10:19 AM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

There is no date picker in 2003. You can add a calendar control and some VBA to insert the selected date in the document.
The calendar control can be found at Insert > Object > Calendar control

To do the VBA, start by typing 11 characters in the doc where you want the date to be displayed (these 11 characters will be replaced by the date).
Turn on the macro recorder and press Ctrl+Home to go to the top of the doc, then use the keyboard to navigate to and select the 11 characters.
Turn off the recorder.
View the macro code and copy the lines that start with "Selection"
Exit the code window
Double click on the calendar control
Between the Private Sub and End Sub lines, paste the lines from the previous macro
Just before the End Sub line, add this line:
Code:
    Selection.Text = Format(Calendar1.Value, "mmm dd yyyy")
The code will resemble:
Code:
Private Sub Calendar1_Click()
    Selection.HomeKey Unit:=wdStory
    Selection.MoveDown Unit:=wdLine, Count:=10
    Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend
    Selection.Text = Format(Calendar1.Value, "mmm dd yyyy")
End Sub
Return to Excel
Exit design mode of the Calendar Control
Test
If it works, delete the original macro that you recorded.
Reply With Quote
  #3  
Old 09-27-2010, 11:41 AM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default

Hi,

I followed the steps but it places the date somewhere else and not at the 11 characters place. Here is the VBA code that I have.

code:

Private Sub Calendar1_Click()
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=10
Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend
Selection.Text = Format(Calendar1.Value, "mmm dd yyyy")
Selection.MoveDown Unit:=wdLine, Count:=54
Selection.MoveRight Unit:=wdCharacter, Count:=15
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend
Selection.Text = Format(Calendar1.Value, "mmm dd yyyy")
End Sub

Thanks for your help.
Reply With Quote
  #4  
Old 09-27-2010, 12:22 PM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

You have a couple of lines in there that are repeated, but should only be present once. I think you used my code and tacked yours on the end.

Start over.



Turn on the macro recorder and do these steps:
  1. Go to the top of the document using Ctrl+Home.
  2. Use arrow keys to get to the spot in your document containing the 11 characters.
  3. Use Shift+arrow key to select the 11 characters
Stop recording.

Then post that code.
Reply With Quote
  #5  
Old 09-27-2010, 12:27 PM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

By the way, I hope I'm not wasting your time. This code assumes the document will not change...
the code will always navigate a number of lines down and a number of characters to the right, then select 11 characters and replace them with a date.

If the 11 characters will move due to additions or deletions above them, we'll need to do it differently.
Reply With Quote
  #6  
Old 09-27-2010, 12:39 PM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default

Actually the document will change as it is a template and users will be filling up the fields. Do we need a different code for this?

The Date fields are somewhere in between the documents.

Than you !
Reply With Quote
  #7  
Old 09-27-2010, 12:49 PM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

You could type this text in the document where you want the date:

Date: TheDateMark

(that is, the word "date", a colon, a space, and then 11 characters to be replaced by the code)

This code will find the text Date<space>:, and replace the 11 characters that follow it with the date.

Code:
 
Private Sub Calendar1_Click()
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "Date: "
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend
    Selection.Text = Format(Calendar1.Value, "mmm dd yyyy")
End Sub
Reply With Quote
  #8  
Old 09-27-2010, 12:56 PM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default

Yes, this does replace the date with one selected in the calendar. Is it possible to add an additional calender in the document. will the code remain the same?

Thank you !
Reply With Quote
  #9  
Old 09-27-2010, 01:06 PM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

If the second calendar is for a second date field, just use different text to mark the beginning of the date (don't use Date: again) in both the document and the code for the second calendar.
Reply With Quote
  #10  
Old 09-27-2010, 01:22 PM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default

Thank you very much ! The code works but the only thing left is that I need to protect the document as I have inserted some form controls like drop down lists in the template. Now when I select a date in the calendar, it gives a runtime error.

I am guessing this has to be a limitation within word.
Reply With Quote
  #11  
Old 09-27-2010, 02:17 PM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

Record a macro that unprotects the doc.
Record a macro that protects the doc.

Paste the unprotect code to the start of the Calendar code
Paste the protect code at the end of the calendar code.

So when the calendar is clicked, the code will unprotect, do the date, then re-protect.
Reply With Quote
  #12  
Old 09-28-2010, 09:45 AM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default

I am trying to use the second calendar for a second date and as you mentioned I used 2 different texts for the dates which are

1. "EffectiveDate: "
2. "ExpirationDate:"

In this case only the first calendar works and the 2nd calendar is set to the first calendars date only when clicked.

How will I be able to overcome this.

Thank you !
Reply With Quote
  #13  
Old 09-28-2010, 04:17 PM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

By default the first calendar you insert is named Calendar1
By default the second calendar you insert is named Calendar2
(right-click on a calendar and choose Properties to see this)

So if Calendar1 is for EffectiveDate: , the code should look like:

Code:
Private Sub Calendar1_Click()
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "EffectiveDate: "
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=11, Extend:=wdExtend
    Selection.Text = Format(Calendar1.Value, "mmm dd yyyy")
End Sub
If the ExpirationDate: calendar is named Calendar2, then the code will be like the above, with three exceptions... the calendar name (twice) and the text to find. I suspect you did not edit the final line to be the value for Calendar2.
Reply With Quote
  #14  
Old 09-29-2010, 08:07 AM
nashville nashville is offline word 2003 date picker Windows XP word 2003 date picker Office 2003
Novice
word 2003 date picker
 
Join Date: Sep 2010
Posts: 8
nashville is on a distinguished road
Default

Sorry for the trouble but I believe we may not have to use macros in the form/template. Is there a way without using macros, for users to simply enter the date? What form do I need to set for users to input the date into the field and avoid having them enter text (e.g using a text box)
Reply With Quote
  #15  
Old 09-29-2010, 10:10 AM
Kimberly Kimberly is offline word 2003 date picker Windows 7 word 2003 date picker Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

"I believe we may not have to use macros in the form/template" What did you have in mind? There is no date picker built-in in versions before 2007. The Insert menu just lets you insert the current date. Other than typing the date, what would there be?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculations using values from date picker controls Inkarnate Word 0 06-09-2010 07:16 AM
Date Function in word? aligahk06 Word 1 04-21-2010 06:33 AM
Word 2007 date and time picker dmcohio Word 2 04-09-2010 04:13 AM
new appointment date always reverts back to today's date msills Outlook 0 08-24-2007 08:57 AM
word 2003 date picker Imported message date change to today's date promark Outlook 1 12-23-2005 07:21 AM


All times are GMT -7. The time now is 06:45 PM.


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