Question:

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

by  |  earlier

0 LIKES UnLike

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?

 Tags:

   Report

2 ANSWERS


  1. 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)


  2. 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.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.