Formatting Dates without using Mask in a textbox. RRS feed

  • Question

  • Hello everyone,

    I have a textbox on on an access form bound to a database.
    I know I can use the masked or SQL to get the date formatted that is inserted into the database.

    However, I do not want to use mask for formatting. What I really need is for a user to type the following; example: 100111

    and on Lostfocus, the date which is text will instantly become formatted to the following: 10/01/2011.

    Is this possible?

    Thanks everyone!



    Saturday, October 1, 2011 9:08 AM


All replies

  • The following code get request a date in your "short" format and produce both a Date and a String for that date:


    Sub demo()
    Dim output1 As Date, output2 As String, input1 As Long
    input1 = Application.InputBox(Prompt:="enter value", Type:=1)
    output1 = DateSerial(2000 + Right(input1, 2), Left(input1, 2), Mid(input1, 3, 2))
    output2 = Left(input1, 2) & "/" & Mid(input1, 3, 2) & "/" & "20" & Right(input1, 2)
    MsgBox output1 & vbCrLf & output2
    End Sub

    Saturday, October 1, 2011 5:58 PM
  • Hi Synthologic,


    You might use a build-in Input Mask for your Date field, which does the trick for you:



    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Tuesday, January 31, 2012 4:10 AM