MS access: need to insert a preset value into a Date field?

Does anyone know how to do this? i need to show the word "Empty" in red before the dates are entered... can access do this?

Comments

  • What you can do is store the date as a string, but you will have to validate the data yourself.

    When you need to data calculations, you will also need to change the string type to data type using DateValue() function before using any of the time and date manipulation functions (Year(), Month(), Day(), DateAdd(), DateDiff() etc)

    Should you choose to do so, then assign "Empty" as the default Value in the table properties for that field (call it SomeDate, not Date).

    To the On GotFocus event handler stub, you add

    Private Sub txtSomeDate_GotFocus()

      txtSomeDate = ""

    End Sub

    As a completion, you could also add, should someone decide to click on the field but not add a date,

    Private Sub txtSomeDate_LostFocus()

      txtSomeDate = "Empty"

    End Sub

    Finally, use conditional formatting to change the colour to Red:

    Select the text box (in design view) and click on Format, Conditional Formatting:

    The steps from then on are obvious.

  • It's impossible, why?

    1. "Empty" - a string (not allowed in the data type DATE/TIME)

    2. You can only set STRING or DATE/TIME data type (you can't have both)

Sign In or Register to comment.