+ Reply to Thread
Results 1 to 7 of 7

Date Format in Userform Textbox

  1. #1
    Registered User
    Join Date
    09-10-2017
    Location
    Mansfield, UK
    MS-Off Ver
    2007
    Posts
    23

    Date Format in Userform Textbox

    Hi,

    I'm having problems with date format in userform text boxes. I fill in the date in the text box and then when I ok it the date is stored in cell on the worksheet which is formatted to date DD/MM/YYYY. when I reopen the user form the date then repopulated back into the same text box but sometimes the format changes.

    For example - if I enter 15/09/2017 in the userform, it appears this way in the cell and also in the text box when I reload it. If I enter 01/09/2017 in the userform it appears in the cell as 09/01/2017 so it looks like the format has changed.

    The control panel has the date settings as UK and the date format is set in the cell so i think I have to change the formatting in the textbox but I'm not sure how to do this and if it should be when I initialize the userform, when I run th subs based on the userform or both.

    there is more than 1 textbox in the userform that needs to do this but not all of them.

    example of the code use on intializing is, PCard1 is the textbox:

    Please Login or Register  to view this content.
    Any help would be greatly appreciated

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Date Format in Userform Textbox

    How are you putting the date(s) from the userform in cells on the worksheet?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-10-2017
    Location
    Mansfield, UK
    MS-Off Ver
    2007
    Posts
    23

    Re: Date Format in Userform Textbox

    I've attached a picture of the userform. Each checkbox down the left activates a frame and I run a loop through each frame. I've pasted the first section of the code below as well, it just repeats for each frame. There's no doubt a more efficient way to do it but I'm pretty new at this. some of the textboxes use a date and some don't.

    Driver List.JPG

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Date Format in Userform Textbox

    When putting a 'text' date value from a textbox into a cell you should convert the value to a 'real' date using DateValue or CDate.

  5. #5
    Registered User
    Join Date
    09-10-2017
    Location
    Mansfield, UK
    MS-Off Ver
    2007
    Posts
    23

    Re: Date Format in Userform Textbox

    I've updated the code for the OK button to load the info into the spreadsheet to:

    Please Login or Register  to view this content.
    it works fine when so the date format is in the worksheet as in the userform but when I reload the userform the format changes again e.g if I put 09/01/2017 in the userform it appears the same on the worksheet but when I reload the userform it appears as 01/09/2017.

    the code when initializing the userform is now:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Date Format in Userform Textbox

    Why are you using CDate when populating the userform?

    Try this.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-10-2017
    Location
    Mansfield, UK
    MS-Off Ver
    2007
    Posts
    23

    Re: Date Format in Userform Textbox

    perfect. Thank you. Before using Cdate I was doing as you said but using .value NOT .text and had the same problem. Sorry if it was a schoolboy error

+ 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] change format date field in textbox userform
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2016, 08:09 AM
  2. [SOLVED] Date format in textbox userform
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2016, 06:57 AM
  3. [SOLVED] Userform textbox & date format question
    By Crispy85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2016, 03:44 AM
  4. [SOLVED] Excel 2010 - Userform - display date from textbox in a label or textbox in 'ddd' format
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2015, 10:54 PM
  5. [SOLVED] Userform Textbox Date Format
    By saban1974 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2014, 10:52 AM
  6. [SOLVED] Excel 2007, Userform Textbox Date Format and Calendar Control Userform
    By riffology in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2014, 06:18 PM
  7. Date Format for textbox in userform
    By processchip in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2011, 06:42 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