Consulting

Results 1 to 7 of 7

Thread: txtDate

  1. #1
    VBAX Regular
    Joined
    Oct 2009
    Posts
    17
    Location

    txtDate

    Hi all,

    Sorry - I've searched for the answer to this, but can't find it in this forum or on the net generally.

    Does "txtDate = Date" return the format set in Control Panel/Regional Settings? If not, how would I change dates entered in a userform from US format to UK format?

    I'd appreciate any advice.

    Many thanks,

    Ronmac

  2. #2
    VBAX Regular
    Joined
    Oct 2009
    Posts
    17
    Location

    txtDate

    I guess I've answered my own question - I've just checked my regional settings and they are already set to UK format. Short date is set to 04/11/09 and Long date to 04 November 2009 - however, any date input is appearing in US format.

    I wondered if "txtDate = Date" required an addition such as "Date=UK" or some such code.

    Regards,

    Ronmac

  3. #3
    VBAX Regular
    Joined
    Oct 2009
    Posts
    17
    Location

    SOLUTION: txtDate

    Hi,

    I've found the answer through trial and error.

    I needed to add the following to my code:

    Dim LDate as Long
    LDate = Date

    then, instead of "txtDate = Date" I changed it to "txtDate = LDate". It now returns the date format from my system.

    Cheers,

    Ronmac

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Is this in a TextBox on a UserForm?

  5. #5
    VBAX Regular
    Joined
    Oct 2009
    Posts
    17
    Location

    TxtDate

    Hi GTO,

    Yes, it is.

    I sent a further msg stating that (having omitted it from my previous email) but it doesn't seem to have made it to the forum! I really must engage my brain.

    Regards,

    Ron

  6. #6
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by Ronmac
    Dim LDate as Long
    LDate = Date
    then, instead of "txtDate = Date" I changed it to "txtDate = LDate". It now returns the date format from my system.
    Greetings,

    I must have been posting slow, as I had not seen your post at #4 when I asked. If it is solved, that is great

    In case not, I would think that returning a Long to the text box would get something like 40122 in the textbox? I am probably staring straight at what I'm missing...

    Anyways, I was just going to suggest something like
    [vba]
    Private Sub UserForm_Initialize()
    Dim lDate As Long

    lDate = Date
    Me.TextBox1.Value = lDate
    Me.TextBox2.Value = Format(Date, "dd/mm/yyyy")
    End Sub
    [/vba]

    Have a great day,

    Mark

  7. #7
    VBAX Regular
    Joined
    Oct 2009
    Posts
    17
    Location

    TxtDate

    Hi Mark,

    Yes, I've solved it, but many thanks for taking the trouble to look at the problem. I've replied to your answer to my other question, too, which worked perfectly.

    When the macro was run, txtDate = Date placed "11/04/09" in the appropriate textbox on my userform. Because that could be interpreted as 11th April 2009 (and not 4th November 2009 when the data was actually input) I needed the box to show (and insert) the UK format date.

    By simply changing the code as I've said, it did both.

    Again, many thanks for your trouble.

    Kind regards,

    Ron

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •