Force Current Year

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tbeers
    New Member
    • Nov 2007
    • 63

    Force Current Year

    Good morning.

    I am running a timecard program in Access 2007 and it seems that the users have trouble entering the correct year when entering the date in the date field. Date field entry format is mm/dd/yy and is displayed as mm/dd/yyyy.

    How can I force the current year to be entered?

    Thanks

    TomB
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Tom.

    Try to reconstruct date entered by user with DateSerial() function.
    Day() and Month() functions will help you to extract correspondent values from user input while Year(Date()) will give you current year.

    Regards,
    Fish.

    Comment

    • MindBender77
      New Member
      • Jul 2007
      • 233

      #3
      Originally posted by tbeers
      Date field entry format is mm/dd/yy and is displayed as mm/dd/yyyy.

      How can I force the current year to be entered?
      My first question is what type of control is the date field in ie. Textbox?

      Second, why do you need to have them enter this manually. You could simply have the control source of the textbox =Date(). Which will produce the current date automatically.

      Bender

      Comment

      • tbeers
        New Member
        • Nov 2007
        • 63

        #4
        force current year

        I have the textbox = date() set, but sometimes they enter time for different days other than the current day. I just want an alert or procedure that keeps any year other than current year from being entered.

        -Thanks

        -Tom

        Comment

        • ChipR
          Recognized Expert Top Contributor
          • Jul 2008
          • 1289

          #5
          In the text box's validation rule put:

          Format([text0],"yy")=Format(D ate(),"yy")

          Comment

          • MindBender77
            New Member
            • Jul 2007
            • 233

            #6
            Originally posted by tbeers
            I just want an alert or procedure that keeps any year other than current year from being entered.
            You could set the enable property of the textbox to "false" which should prevent users from changing anything you don't want them to change. It will just gray out the textbox but, retain the data.

            Or something like this in OnExit event of your textbox:
            Code:
            If format(" & Textbox1 & ", "yy")  <> format(Date,"yy") Then
            msgbox("Please Enter the Current year.")
            docmd.cancelevent
            textbox1.setfocus
            else
            'do something here.........
            end if
            Note, this is untested.

            HTH,
            Bender

            Comment

            Working...