+ Reply to Thread
Results 1 to 11 of 11

Force a user to enter a date instead of text

  1. #1
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Force a user to enter a date instead of text

    Hi,

    In a userform i have 2 textboxes that need to be populated with a date.
    Is there a simple script to force a user to enter a date in format dd-mm-yyyy?

    When commandbutton1 is clicked, it should check if the textbox is populated with a correct date. Otherwise give a messagebox that says something like "Please enter a correct date."

    thanks!
    Last edited by Crispy85; 12-08-2016 at 07:18 AM.

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Force a user to enter a date instead of text

    Please Login or Register  to view this content.
    Repeat for 2nd text box
    Last edited by nigelog; 12-08-2016 at 07:24 AM.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Force a user to enter a date instead of text

    In the Command Button Click event you could use

    Please Login or Register  to view this content.
    However you should try to avoid allowing users to enter text for stuff like dates which require a strict format. Instead use one of the many calendar forms you'll find if you google around, or keep it simple and have three listboxes to contain the numbers 1-31, 1-12 and 2016-whatever year is necessary. Then use the numbers selected in the list boxes to create the date. The days listbox could be made to react to the number of days in the month if you force the month listbox to be the first to be colmpleted.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Force a user to enter a date instead of text

    Hi all,

    Thanks for the reply's!!
    I just found out there is a kind of template calendar that i can add to additional controls.

    Please Login or Register  to view this content.
    After selecting a date it closes the calendar form but doesn't populate Texbox1 with the picked date.

    Please Login or Register  to view this content.
    Do you know why it doesn't populate my textbox?

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Force a user to enter a date instead of text

    If the button is on the calendar form, then you need to qualify the reference to the textbox with its parent userform name.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Force a user to enter a date instead of text

    Thanks all!!!

  7. #7
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Force a user to enter a date instead of text

    One more last question.

    I have more than one textbox for a date in my userform.
    if one of these is clicked the calendar appears.
    but how can i fill the active control with the chosen date?

    I tried:
    Please Login or Register  to view this content.
    But this doesn't work

  8. #8
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Force a user to enter a date instead of text

    Second calender attached to second textbox ??

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Force a user to enter a date instead of text

    ....or create Variables for each date that you capture with the calendar, identifying them with date1, date2...etc and then use the variables to populate the text boxes.

    However why are you persisting with text boxes which are capable of being changed. If you just want to record the date on the userform then use the caption property of a Label.

  10. #10
    Forum Contributor
    Join Date
    06-14-2013
    Location
    jk
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Force a user to enter a date instead of text

    Hi all,

    What if my dates are entered in a regular inputbox?
    Like the script below, how can i give an error message if the date is not in format dd-mm-yyyy?

    Please Login or Register  to view this content.

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Force a user to enter a date instead of text

    Hi,

    One way
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] When an option is selected from list, it should force the user to enter data elsewhere
    By exceltriumph in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-05-2016, 07:20 AM
  2. [SOLVED] Prefill text box in userform with today's date but allow user to enter unique date
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-02-2014, 09:17 AM
  3. [SOLVED] Force user to enter certain characters
    By NJH88 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-08-2013, 09:33 AM
  4. Force user to enter specific alphabets in userform
    By saji in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2013, 10:22 AM
  5. [SOLVED] if statement to force user enter string without spacing
    By rename in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-20-2012, 05:20 AM
  6. Replies: 1
    Last Post: 06-15-2011, 02:36 AM
  7. Force user to enter value in cells
    By staples in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2009, 05:17 AM

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