+ Reply to Thread
Results 1 to 28 of 28

Date/Time Picker

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Date/Time Picker

    On the attachment i have a userform which pops up when cell B2 is selected. It is a month view from the additional controls on the control toolbox. I've also added a couple of text boxes with spin buttons.

    A few amendments i want to make to it are:
    • User form pops up next cell B2
    • 'Enter button' enters date and time into cell B2
    • Spin buttons increase/decrease hour field in incremnts of 1 and minutes field in increments of 5

    Thanks,
    Adam.
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,

    This seems like a simple question with a simple answer. The question is simple but the answer isn't. Have a look a Chip Pearson's site about how to do this.

    Form Positioner
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Date/Time Picker

    There's an example of using comboboxes to add times here

    Combo_Time.zip

    Also, be aware that the Datepicker can be problematical when distributing your workbook if the end user does not have the control installed on their computer.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    I shall try and address the combo time idea first. This is ok but i would ideally like it to work like i originally said with spin buttons to increase/decrease the hours and minutes by set increments. Would this be possible?

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,

    Here is the code for the SpinButtons and the Enter button. This has already been added to the attached workbook.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: Date/Time Picker

    For testing
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Thank you for your replies. I particularly like Leith's version and would like to ask a few questions to improve further...
    • Can i add code where if the user presses 'esc' button, the form closes.
    • Format the hrs and mins text boxes to "00", so numbers like 1 becomes 01.
    • Put a validation on the text boxes so the user can only enter 00-23 hours and 00-59 mins and also could this range loop around itself, i.e. if i use the spin buttons i can go up from 23 hours to 00 hours and so on.
    • Have the ability to manually enter mins between the 5 mins increments and then be able to enter this into the cell value
    • Enter button closes form once pressed.
    • When calendar opens it shows the current date and time in the cell value.

    I am finding the form positioner that was originally posted a little tricky to do so i wil come back to that once i have the form working as i want it to.

    Also, if the computer i want to use the datepicker on on does not have this control installed can i install it on this computer so it can be used?

    Thanks,
    Adam.

    Note: I have greyed out the points that have been resolved.
    Last edited by adam2308; 08-30-2009 at 04:48 PM.

  8. #8
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: Date/Time Picker

    I try to help
    Can i add code where if the user presses 'esc' button, the form closes.
    When workbook opens it shows the current date and time in the cell value.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Thanks for your efforts Trucker10 but your version tries to close the workbook when pressing escape (i have found out how to do this now anyway) and showing the current time and date when opening the workbook is not what i am actually looking for. What i want there is when the form is opened that the calendar shows the date currently in cell B2, if no date is in the cell then todays date should be selected.

    I have also fixed the form to close on pressing the enter button.

    Note: I have greyed out the the bullet points above that have now been resolved.

    Attached is the latest version where i am up to.
    Attached Files Attached Files
    Last edited by adam2308; 08-27-2009 at 04:56 PM.

  10. #10
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: Date/Time Picker

    Quote Originally Posted by adam2308 View Post
    What i want there is when the form is opened that the calendar shows the date currently in cell B2, if no date is in the cell then todays date should be selected.
    I had the wrong form translated into Dutch ( formulier ) and not user form
    try this one
    Please Login or Register  to view this content.
    and for the user to close
    Please Login or Register  to view this content.
    Last edited by trucker10; 08-28-2009 at 04:50 AM.

  11. #11
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Thanks for this Trucker.

    Code:

    Private Sub UserForm_Activate()
    If IsDate(ActiveCell.Value) Then
    MonthView1.Value = DateValue(Range("B2"))
    Else
    [B2].FormulaR1C1 = Format(Now, "dd-mm-yyyy hh:mm:ss")
    End If
    End Sub
    This keeps the current date in the active cell on the date picker just fine. I would also like the hours and mins textboxes to show the current time. i.e if the date/time in cell B2 is "29/08/2009 20:35" then textbox1 would show "20" and textbox2 would show "35".

    I altered the code to following...

    Please Login or Register  to view this content.
    This code works for textbox1 but of course textbox2 displays the month of the value in cell B2. Can i format textbox2 to just the mins "35"?

    Attached is my latest version...
    Thanks guys.
    Attached Files Attached Files
    Last edited by adam2308; 08-28-2009 at 06:34 PM.

  12. #12
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: Date/Time Picker

    with 2 additional cells
    Attached Files Attached Files
    Last edited by trucker10; 08-29-2009 at 05:45 AM. Reason: new upload

  13. #13
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    thanks trucker.. thats great. I have merged your changes into my latest version. Below is the outstanding issues i have with my form and attached is the latest version, would appreciate it if anyone could help...
    • Put a validation on the text boxes so the user can only enter 00-23 hours and 00-59 mins and also could this range loop around itself, i.e. if i use the spin buttons i can go up from 23 hours to 00 hours and so on.
    • When the user form opens the hours and mins textboxes show the current values in cells D2 and E2 but if i use the spin buttons to move the hour or mins up the value starts again at zero rather than moving up one increment from the current value in the cells.
    Attached Files Attached Files
    Last edited by adam2308; 08-30-2009 at 06:56 PM.

  14. #14
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Can anyone help with my outstanding issues please?

  15. #15
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: Date/Time Picker

    Quote Originally Posted by adam2308 View Post
    Can anyone help with my outstanding issues please?
    the unresolved issue ? > validation on the text boxes ? or ??

  16. #16
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    These are my outstanding issues (i have resolved part of the first point, the bit i am stuck on here is the part where i want the the range of hours to loop around itself).

    [*] Put a validation on the text boxes so the user can only enter 00-23 hours and 00-59 mins and also could this range loop around itself, i.e. if i use the spin buttons i can go up from 23 hours to 00 hours and so on.
    [*] When the user form opens the hours and mins textboxes show the current values in cells D2 and E2 but if i use the spin buttons to move the hour or mins up the value starts again at zero rather than moving up one increment from the current value in the cells.

  17. #17
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Can anyone help with these last two points? Any questions please ask.
    Last edited by adam2308; 08-31-2009 at 06:00 PM.

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,,

    Have a look at the attached workbook. Let me know if you need anything else changed or added.
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Smile Re: Date/Time Picker

    Hi Leith,

    Thanks for this, it seems you have managed to sort the problem we had with the date being converted to US style.

    I still have a couple of little points i would like to fix if possible before i finish this thread if i may...
    • On a previous version you added some code into the calendar that highlighted the selected date bold. Could add this back in as i quite liked that. Is it also possible to bold teh days of the week across the top of the calendar?
    • I'd like it so that the minutes text box increased/decreased in 5 minute increments from whatever number is in the textbox, i.e. if the text box is on 43 and user presses the spin-button up, the minutes would go... 43, 48, 53, 58, 03 etc not 43, 45, 50, 55
    • Is it possible to make the textboxes loop around the range set in them For example in the minutes box was on 53, i would like it i pressed spin-button up then the minutes textbox would go... 53, 58, 03, 08 etc.

    Thanks.
    Last edited by adam2308; 09-04-2009 at 05:37 PM.

  20. #20
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,

    I think it is possible to do the TextBox loop. I'll need some time to play with it.

  21. #21
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    ok Leith, whenever you have got the time.

    Thanks for your help i really appreciate it!!

  22. #22
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,

    OK, got the SpinButtons working in sync with the TextBoxes and the bold datre is back. Here is code for the UserForm.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  23. #23
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Leith... You are a genius!!

    Is it also possible to bold the days of the week across the top of the calendar? They just don't seem to clear at the minute.

    Cherers,
    Adam.

  24. #24
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,

    To increase the contrast of the weekday names, change the TitleBackColor property. You can also change the month/year color using the TitleForeColor property. In the attached workbook, white and green are used. Play around and see what color combinations you like best.
    Attached Files Attached Files

  25. #25
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    excellent... i can do this bit myself !!!

    I now just need to see how this works on the comp's in our office at work. I'll check tomorrow and let you know.

    Thanks again!!

  26. #26
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    ok... i have just found a couple of errors with the form.
    • If either the hours or minutes text box is empty when the user presses the 'enter' command button an error occurs. If possible i'd like a msg box to appear saying "start time not entered correctly." and the user is taken back to the form.
    • If form opened when cell B2 is empty then no time is entered in the text boxes and if the user tries to use the spin buttons then the following error appears...
      "Run-Time Error '13':
      Type Mismatch
      I'd like if the textboxes are empty then the spin buttons would move the text boxes up or down from zero, if possible.

  27. #27
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Date/Time Picker

    Hello adam2308,

    I took more time to make some more improvements. The validation has been added to the hours and minutes. If the text box is empty a value of "00" is automatically entered. If the value is a negative number or greater than 23 for hours or 59 for minutes, an error message is displayed and focus is set back to the text box. I added icons to the Enter and Cancel buttons and accelerator keys. You can type ALT+C to Cancel and ALT+E to Enter the time. Here is the UserForm code complete with annotations.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    02-20-2009
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    467

    Re: Date/Time Picker

    Hi Leith,

    Thanks for fixing those errors and the improvements you have added look really cool too!

    I didn't get chance to try this on the comp's at work today but hopefully i will do tomorrow and i'll let you know how i get on.

    Thanks again, i've learned an awful lot from this thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1