Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Change date format (2000 / 20003)

    Hi,

    Is it possible to change a date default in a text box to 8 digit format i.e. if a date is entered as 1/8/08 or 01/8/08 or 1/8/2008 or any other combination it ends up like 01/08/2008

    I was using a series of if commands (see below) but this caused a problem if the date required is prior to 2000 and seems to be way more code than is nessacary

    Many thanks

    'Converts 4 and 6 digit dates to 8 digit format
    If CommandBars("SLS").Controls(4).Text Like "[0-9][0-9]/[0-9][0-9]/[0-9][0-9]" Then
    CommandBars("SLS").Controls(4).Text = Left(CommandBars("SLS").Controls(4).Text, 6) & _
    Mid(Date, 7, 2) & Right(CommandBars("SLS").Controls(4).Text, 2)

    ElseIf CommandBars("SLS").Controls(4).Text Like "[0-9]/[0-9]/[0-9][0-9]" Then
    CommandBars("SLS").Controls(4).Text = "0" & Left(CommandBars("SLS").Controls(4).Text, 2) & _
    "0" & Mid(CommandBars("SLS").Controls(4).Text, 3, 2) & Mid(Date, 7, 2) & _
    Right(CommandBars("SLS").Controls(4).Text, 2)
    End If
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change date format (2000 / 20003)

    Try

    With CommandBars("SLS").Controls(4)
    .Text = Format(.Text, "dd/mm/yyyy")
    End With

  3. #3
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Change date format (2000 / 20003)

    Perfect thanks
    Regards
    Gerbil (AKA Kevin)

Posting Permissions

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