Share via

Date picker value

Anonymous
2012-10-12T18:21:14+00:00

Hi, I have a date picker (DTPicker1) on a user form.  In the document I have a docvariable ("DateEnd"). 

The starting value of the date picker (in properties) is 10/12/2012

In the userform code this runs when command button is clicked:

        ActiveDocument.Variables("DateEnd").Value = Format(DTPicker1.Value, "mmmm dd, yyyy")

        ActiveDocument.Range.Fields.Update

The docvariable populates with December 31, 1899 no matter what date I put in the picker box. 

If I run this code:

        MsgBox ufrmMain.DTPicker1.Value

it returns:  12:00:00 AM

I have other docvariables that are text which populate correctly from text boxes.

If I don't have the format code and populate with the value it returns 12:00:00 AM

What am I doing wrong with the date picker - how do I get the date?

Thank you.

 EDIT: The format of the date picker is set to short date.

EDIT - naturally I found the solution right after I posted.  I need to add the format switch to my docvariable field:  @ "MMMM dd, yyyy"

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2012-10-13T04:27:43+00:00

Or use the correct formatting switch with DTPicker1.Value

Format(DTPicker1.Value, "MMMM dd, yyyy")

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more