#1
|
|||
|
|||
Date Picker time in a protected Word form
I've got a date picker field in a protected Word form. Protection is set to "filling in forms".
I've set up the date picker via properties to format the date/time as M/d/yyyy h:mm:ss am/pm. I need the time to appear once the date is picked. The issue is that when the date picker is selected and today's' date is chosen, the actual time is not populated: it defaults to 12:00:00 AM and not the actual time. The date is correct. How can I use the date picker and have the actual time shown when someone chooses the date? Thank you! |
#2
|
|||
|
|||
There is no such thing as a Time picker. You could perhaps use the CC OnExit event as follows:
Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean) If CC.Type = wdContentControlDate Then If IsDate(CC.Range.Text) Then If CC.DateDisplayFormat = "M/d/yyyy h:mm:ss am/pm" Then CC.Range.Text = Format(Now, "M/d/yyyy h:mm:ss am/pm") End If End If End If End Sub |
#3
|
||||
|
||||
Quote:
I note that Greg refers to the use of a content control. Do note that content controls and formfields should not be used in the same document. They weren't designed to work that way and doing so is a known source of problems.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
||||
|
||||
Wolfgrrl
Greg's code will add the time as you asked however it also overrides the date to place today's date as the date. This may be what you intended but it does make it pretty much pointless for the user to select a date in the Date Picker when simply exiting the CC overrides the chosen date. Did you want today's date as well as the time? Or did you want to preserve the date that the user picks and include the current time (eg exactly 24 hours from now)?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Andrew, good point. This might do better if picking a date other than today.
Code:
Private Sub Document_ContentControlOnExit(ByVal CC As ContentControl, Cancel As Boolean) If CC.Type = wdContentControlDate Then If IsDate(CC.Range.Text) Then If CC.DateDisplayFormat = "M/d/yyyy h:mm:ss am/pm" Then CC.Range.Text = Format(CDate(CC.Range.Text), "M/d/yyyy") & " " & Time End If End If End If End Sub |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
I cannot figure out how to add a date picker, among others, in MS Word 2016 on my mac | Randree | Word | 3 | 04-25-2017 09:44 PM |
Possible to link a date picker to another date picker? | tubbz | Word | 0 | 05-07-2014 01:23 PM |
Word form w/ autopopulated date/time | Dendalee | Word | 1 | 10-24-2012 11:40 PM |
word 2003 date picker | nashville | Word | 16 | 04-06-2012 04:12 AM |
Word 2007 date and time picker | dmcohio | Word | 2 | 04-09-2010 04:13 AM |