+ Reply to Thread
Results 1 to 6 of 6

Correct date format from textbox in form to table

  1. #1
    Registered User
    Join Date
    06-25-2014
    Location
    Denmark
    MS-Off Ver
    365 (Win and Mac)
    Posts
    20

    Correct date format from textbox in form to table

    Hey all.

    I have this little problem with a userform. It contains two textboxes where the users fill in a start date and a end date.
    When I send the dates from these two textboxes to my table it reads it "mm-dd-yyyy" and I want it "dd-mm-yyyy".
    I have tried setting the format both in form and in table.
    Simple I think, but I just can't figure it out!! As you can see in the code I have tried a few things. Thanks in advance.
    (And yes, I am pretty new to VBA)

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Correct date format from textbox in form to table

    Hi and Welcome,

    Without seeing a sample workbook, it's difficult to pinpoint the problem. If you don't need to do any calculations on the dates you can format dates as text in the worksheet, by doing something like:
    Please Login or Register  to view this content.
    Lewis

  3. #3
    Registered User
    Join Date
    06-25-2014
    Location
    Denmark
    MS-Off Ver
    365 (Win and Mac)
    Posts
    20

    Re: Correct date format from textbox in form to table

    Booking_System_Sample.xlsm

    Hey LJMetzger

    Thanks for your quick response.
    It is a nice workaround only for "display"
    I have attached a sample of my workbook, so you can see what I am working on.
    It is a booking system with a chart taking the dates from the table i push dates into.

    Take a look, it is not nearly done yet, but I am working on it.

  4. #4
    Registered User
    Join Date
    06-25-2014
    Location
    Denmark
    MS-Off Ver
    365 (Win and Mac)
    Posts
    20

    Re: Correct date format from textbox in form to table

    Hey LJMetzger.

    I have fixed the problem with the use of CDate Function.
    Looks like this when i copy the date to the worksheet.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Correct date format from textbox in form to table

    Hi eddijensen,

    I'm glad you have it working, however, you may be masking other problems. I was unable to check the CDate that you used in your previous post, because I think you made some other changes in obtaining the value of 'txtStartUdstyr' and 'txtSlutUdstyr'.

    I have the following observations, which I hope are helpful to you.

    1. I followed the UserForm instructions and entered dates in mm-dd-yyyy format in the UserForm. Using the following code I was able to retrieve the proper dates. I do not know if what I did was affected by my United States computer setting of mm-dd-yyyy vs your Eutopean computer setting which is probably dd-mm-yyyy. I am thinking that the following code is probably independent of the computer setting:
    Please Login or Register  to view this content.
    2. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module.
    This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. dim i as Integer).
    http://www.cpearson.com/excel/DeclaringVariables.aspx

    3. In Columns E and F of Sheet BookingdataUdstyr, you may want to change the format to Custom Format, 'dd-mm-yyyy', which may solve your problem without using the CDate casting conversion.

    Lewis

  6. #6
    Registered User
    Join Date
    06-25-2014
    Location
    Denmark
    MS-Off Ver
    365 (Win and Mac)
    Posts
    20

    Re: Correct date format from textbox in form to table

    Thanks a lot.. Nice article, it gives good sense to minimize the risk of errors..


    Sent from my iPad using Tapatalk

+ 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. Replies: 5
    Last Post: 07-09-2014, 01:29 PM
  2. Correct Date syntax for cell and textbox find
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-09-2012, 12:54 AM
  3. Date off form textbox entering as US format not european
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2009, 08:21 AM
  4. Form Textbox - Reference Different Table/Query
    By NSTurk725 in forum Access Tables & Databases
    Replies: 2
    Last Post: 09-08-2009, 04:37 PM
  5. it is possible to format a Form TextBox Value?
    By jose luis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2005, 06:21 PM

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