Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2020, 11:31 AM
wolfgrrl wolfgrrl is offline Date Picker time in a protected Word form Windows 10 Date Picker time in a protected Word form Office 2010
Novice
Date Picker time in a protected Word form
 
Join Date: May 2019
Posts: 15
wolfgrrl is on a distinguished road
Default 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!
Attached Images
File Type: jpg Annotation 2020-04-07 142711.jpg (15.4 KB, 13 views)
Reply With Quote
  #2  
Old 04-07-2020, 12:15 PM
gmaxey gmaxey is offline Date Picker time in a protected Word form Windows 10 Date Picker time in a protected Word form Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,033
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 04-07-2020, 02:53 PM
macropod's Avatar
macropod macropod is online now Date Picker time in a protected Word form Windows 7 64bit Date Picker time in a protected Word form Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,329
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Quote:
Originally Posted by wolfgrrl View Post
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.
Presumably you're referring to a formfield. A formfield formatted as a date formfield with with output formatted as you describe requires an actual date and time to be input if you want the output to be anything other than today's date and/or 12:00:00 AM.

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
[MS MVP - Word]
Reply With Quote
  #4  
Old 04-07-2020, 05:45 PM
Guessed's Avatar
Guessed Guessed is offline Date Picker time in a protected Word form Windows 10 Date Picker time in a protected Word form Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,565
Guessed is just really niceGuessed is just really niceGuessed is just really niceGuessed is just really niceGuessed is just really nice
Default

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
Reply With Quote
  #5  
Old 04-08-2020, 07:03 AM
gmaxey gmaxey is offline Date Picker time in a protected Word form Windows 10 Date Picker time in a protected Word form Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,033
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Picker time in a protected Word form 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
Date Picker time in a protected Word form Word form w/ autopopulated date/time Dendalee Word 1 10-24-2012 11:40 PM
Date Picker time in a protected Word form 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

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 09:18 PM.


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