Search code examples
ms-accessdatedata-entry

Allow user to separate dates with period in MS Access


I am working with an Access database where I have a form that contains several date entry fields. I have a new user that is used to using a period as a delimiter for dates so instead of "6/22/11" or "6-22-11", they enter "6.22.11". I would like to continue to allow this type of entry, but Access converts "6.22.11" to a time instead of a date. I have tried setting the format on the text box to "Short Date" with no help. I have also tried adding code to the "Lost Focus" event but that is to late since Access has already done the conversion. The "Before Update" event fires before the conversion but will not allow me to change the text in the textbox. Any ideas on how I can allow all three forms of date entry?


Solution

  • your above example

    Private Sub Texto0_KeyPress(KeyAscii As Integer)
        If Chr(KeyAscii) = "." Then
            KeyAscii = Asc("/")
        End If
    End Sub
    

    works for me.

    Another aproximation is play with the BeforeUpdate and AfterUpdate events. In BeforeUpdate you cannot modify de content of the control, but you can set a flag (a variable defined at module/form level) in the AfterUpdate event and change the content: it will trigger again the BeforeUpdate, but in this case, because is flagged you sould ignore it and unflag.