+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    02-02-2010
    Location
    Indianapolis, Indiana, USA
    MS-Off Ver
    Office Pro 2007 at Work - Office 2010 Beta at Home
    Posts
    23

    Date Picker Control will not display Current Date

    I am using a couple of Microsoft Date and Time Picker 6.0 (SP4) controls within my Excel workbook. I would like for these controls to automatically fetch the current date. How can I do this?

    Sorry if this is within the wrong subforum.
    Last edited by SP Brian; 03-16-2010 at 06:57 PM.

  2. #2
    Registered User
    Join Date
    02-02-2010
    Location
    Indianapolis, Indiana, USA
    MS-Off Ver
    Office Pro 2007 at Work - Office 2010 Beta at Home
    Posts
    23

    Re: Date Picker Control will not display Current Date

    Any feedback?

  3. #3
    Forum Moderator romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Alibi
    MS-Off Ver
    All
    Posts
    8,262

    Re: Date Picker Control will not display Current Date

    Where are the controls? On a userform or a worksheet?
    So long, and thanks for all the fish.

  4. #4
    Registered User
    Join Date
    02-02-2010
    Location
    Indianapolis, Indiana, USA
    MS-Off Ver
    Office Pro 2007 at Work - Office 2010 Beta at Home
    Posts
    23

    Re: Date Picker Control will not display Current Date

    Within a worksheet.

  5. #5
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Date Picker Control will not display Current Date

    I thought the default was the current date, try
    Code:
    Private Sub Worksheet_Activate()
    Me.DTPicker1.Value = Date
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  6. #6
    Registered User
    Join Date
    02-02-2010
    Location
    Indianapolis, Indiana, USA
    MS-Off Ver
    Office Pro 2007 at Work - Office 2010 Beta at Home
    Posts
    23

    Re: Date Picker Control will not display Current Date

    Could you break the code down for me, please? Sorry for my ignorance when it comes to code. I know that "sub" means subroutine and that DTPicker1 is the name of the picker and that ".Value" means that I am setting the value of the DTPicker1 to equal "Date". Does "Date" fetch the system date or how does that work?

    Also, what does Private Sub Worksheet_Activate() mean?

  7. #7
    Forum Moderator romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Alibi
    MS-Off Ver
    All
    Posts
    8,262

    Re: Date Picker Control will not display Current Date

    Date() does indeed return the current system date.
    The Worksheet_Activate event fires whenever you activate the worksheet containing the code.
    So long, and thanks for all the fish.

  8. #8
    Registered User
    Join Date
    02-02-2010
    Location
    Indianapolis, Indiana, USA
    MS-Off Ver
    Office Pro 2007 at Work - Office 2010 Beta at Home
    Posts
    23

    Re: Date Picker Control will not display Current Date

    The code works; however, upon opening the .xlsx file the worksheet opened is the one containing the date picker, so the control is only updated with the current date after I enabled ActiveX/Macros and switch to a different sheet then back to the sheet containing the control.

    Is there a way that I can make this take effect upon the user enabling the ActiveX/Macros?
    Last edited by SP Brian; 03-16-2010 at 06:38 PM.

  9. #9
    Forum Moderator romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Alibi
    MS-Off Ver
    All
    Posts
    8,262

    Re: Date Picker Control will not display Current Date

    Yes - you need to use the Workbook_OPen event. This code needs to go into the ThisWorkbook module:
    Code:
    Private Sub Workbook_Open()
    Sheets("Sheet name").DTPicker1.Value = Date
    End Sub
    So long, and thanks for all the fish.

  10. #10
    Registered User
    Join Date
    02-02-2010
    Location
    Indianapolis, Indiana, USA
    MS-Off Ver
    Office Pro 2007 at Work - Office 2010 Beta at Home
    Posts
    23

    Re: Date Picker Control will not display Current Date

    Works like a charm. Thank you!

  11. #11
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    Re: Date Picker Control will not display Current Date

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  12. #12
    Registered User
    Join Date
    03-04-2011
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Date Picker Control will not display Current Date

    What would the code be for putting the date picker in a userform? thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0