Results 1 to 4 of 4
  1. #1
    dotcanada is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Alberta, Canada
    Posts
    44

    Date Display

    Good day.



    I'm trying to see if this is possible.

    I have a Date field in my table called "DateExpired". This field is added to a form. What I want to do is only enter the a 4-digit year and the result to be YYYY-Jul-01. So no matter what year I enter, the result will be on July 1st of that year.

    Is this possible?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Not sure if it can be done exactly as you describe but you could put an unbound text box on the form and have some code in its BeforeUpdate to manipulate the date shown in the "DateExpired" control
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Sure. Here's an example of some steps, but your situation may have to adapt these accordingly.
    My regional DATE setting is DD-MMM-YYYY

    Dim dtConstant as string
    dtConstant ="-Jul-01"

    then when you enter a date, lets call it YourYear which is dimmed as text.
    consider YourYear ="2017"
    then FinalDate = Cdate( yourYear & dtconstant ) and FinalDate will be a Date/time data type

    sample
    Code:
    Sub consyear()
    Dim dtconstant As String: dtconstant = "-Jul-01"
    Dim YourYear As String: YourYear = "2017"
    Dim FinalDate As Date
    FinalDate = CDate(YourYear & dtconstant)
    Debug.Print FinalDate
    End Sub
    Immediate window
    01-Jul-2017


    Locals window
    : FinalDate : #01-Jul-2017# : Date


    Good luck.

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    In AfterUpdate event for DateExpired field

    Me.DateExpired = me.DateExpired & "-Jul-01"

    How many years are you dealing with? If not to many I would create a table call tblYears and have them select the year from a list, that way you don't get wrong numbers entered.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 01-23-2016, 12:29 PM
  2. Replies: 20
    Last Post: 01-13-2015, 02:23 PM
  3. Display a From Date and To Date on a report
    By Sprinter72 in forum Reports
    Replies: 1
    Last Post: 11-23-2014, 11:16 AM
  4. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  5. Replies: 6
    Last Post: 12-27-2012, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums