+ Reply to Thread
Results 1 to 18 of 18

display date format in VBA Userform

  1. #1
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    display date format in VBA Userform

    I have a database in Excel with a Userform. For the reported date, when the user enters the 'reported date' it transfers successfully to the Excel database. However, when a record is called up again (for editing) in the UserForm, the date appears as a serial number. I've searched everywhere to find appropriate vba code that will "force" the entry in the reported date text field to display as a date when the UserForm is opened. Since this is a project for work, I am unable to download any date picker for this project.

    My project is ALMOST complete - except for this dilemma. Can anyone help guide me on what code is needed, and where that code needs to be inserted? I'm extremely new to using VBA and creating UserForms, so this is particularly frustrating for me.

    Thanks!

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

    Re: display date format in VBA Userform

    How are you populating the userform?
    If posting code please use code tags, see here.

  3. #3
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: display date format in VBA Userform

    Please Login or Register  to view this content.
    Change dd/mm/yyyy" to your desired format.
    As you are from Illinois I guess you put the month first. Then it would be mm/dd/yyyy
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    03-28-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    11

    Re: display date format in VBA Userform

    If you are storing the date in Excel it will be converted to the serial number (something in the 40k-50k range). If you are populating the user form using VBA you will need to wrap the data with the Format() function. The following code line populates the text box "ReportDate" with today's date formatted in the US style. You can replace Now() with your reference to the report date:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    I may not have done this properly the first time (please accept my apologies if there are multiple replies). Thank you for your quick reply.

    I have the line of code suggested, and for an initial entry this works just fine. The problem remains if/when I call up an existing entry from the Excel worksheet, which holds the entry. On the Excel worksheet, the date displays just fine. However, if/when I edit the record via the UserForm, the ReportDate still displays as a serial number. Unfortunately, I cannot use DatePicker because of the way IT has configured Excel. I'm not sure where to go from here . . . .

    Thanks in advance for any assistance you can provide.

  6. #6
    Forum Expert
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    2,427

    Re: display date format in VBA Userform

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

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

    Re: display date format in VBA Userform

    GrannyJ

    Can you post the code you are using to retrieve data and display it on the userform?

  8. #8
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    Attached is the sample file I used to learn how to create userforms and the database subsequently created. I use this sample file to test the necessary features/functions that I create on my database.

    For the Incident Date field, I use the following (which works fine for the initial entry):

    Private Sub txtDate_AfterUpdate()
    If IsDate(Me.txtDate.Text) Then
    Me.txtDate.Text = Format(Me.txtDate.Text, "mm/dd/yyyy")
    End If


    End Sub

    It's when I call up an entry from the database that the Incident Date displays the serial number (as stored in the worksheet) instead of in date format.
    I've also seen other sites recommending storing the date as text, but that prohibits me from performing further calculations (such as elapsed time between Incident Date
    and the date the record is added to the database).

    Appreciate any/all suggestions and guidance you can provide this newbie!
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: display date format in VBA Userform

    Like this?
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    WOW! Thanks for the quick reply. I will try the first suggestion to see if/how it works. If no success, I'll then try the second suggestion.

    I will respond accordingly once I've added and/or tested both to let you know what/how it works.

    Thanks again!

  11. #11
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: display date format in VBA Userform

    Keep us informed

  12. #12
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    So now the date displays perfectly when I call up a record. However, when I try to change the date on an existing record, it doesn't transfer/update the worksheet.
    In reality, this shouldn't happen that often. But, if an incorrect incident date is entered, the user needs to be able to update accordingly.

    I pasted the 2nd suggestion in the Edit command as well. Just missing the appropriate update for the Save command.

  13. #13
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: display date format in VBA Userform

    First of all, in the edit code there is no a single line of code to edit changes.
    This is a total new question.
    And now, I remeber, I reworked your userform a few weeks ago (working according to your demands) and you didn't zip, nada with my suggestions.
    It stops for me here.

  14. #14
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    Sorry, but I just posted this question, and uploaded the file this morning. Maybe someone else has posed a similar question, and I missed finding it. I'm sorry if I offended, but I'm new to this forum.

  15. #15
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: display date format in VBA Userform

    Now that I see your registration date, sorry
    Did you use an example from another post,forum?

  16. #16
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    Sir, I have only used the suggested code you provided earlier, which I did respond to and thanked you for. At this time, I've not registered at any other forum!

  17. #17
    Valued Forum Contributor dotchiejack's Avatar
    Join Date
    05-21-2015
    Location
    Antwerp,Belgium
    MS-Off Ver
    2016
    Posts
    507

    Re: display date format in VBA Userform

    Ok,
    If no one is ahead of me I will help you tomorrow, now it is too late here.

  18. #18
    Registered User
    Join Date
    03-23-2021
    Location
    Illinois
    MS-Off Ver
    Office 365
    Posts
    8

    Re: display date format in VBA Userform

    My apologies! I missed seeing your response this morning.
    I will also include this line of code, I believe it would be a replacement under the Submit sub, and will test my updates.

    One thing I thought about is that the report date MAY change each time a user edits a record. If that's the case, it gives me the opportunity to add an additional field for the user to enter the date they are adding a particular record to the database. Then, I can perform the necessary calculations to determine reporting lag time.

    Thanks, again. Allow me at least a day to respond with status (and hopefully, success).

+ 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: 2
    Last Post: 12-07-2016, 02:02 AM
  2. [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
  3. Date Format Of User PC Changes Display format date of Excel File after update
    By waihar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-24-2014, 03:09 AM
  4. [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
  5. [SOLVED] Userform date entered in UK format but showing in US Format in spreadsheet
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-23-2013, 01:59 PM
  6. UserForm - Display todays date
    By stojko89 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-16-2011, 01:38 AM
  7. Userform date format reverting back to us format on change event
    By jpruffle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-10-2009, 12:34 PM

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