Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Feb 2003
    Location
    Renfrewshire, Scotland
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post

    Question Format(Year(Now) strange results in Word 2007 VBA

    Hi All,
    Does anyone have an explanation of this. Found it while migrating some word 2000 templates and code to 2007. The attachment is a screen grab of the VBA watch window, The code Format(Year(Now),"yy") correctly returns "13" but Format(Year(Now)+1,"yy") returns "05" (1.e. 1905) whereas Year(Now)+1 correctly returns 2014. It works fine in Word 2000. It may relate to 1904 date system but I don't use that or have it set in Excel. Any ideas?

    Oops - just did a check It's the SAME in Word 2000
    Attached Files Attached Files
    Last edited by DougieW; 2013-07-28 at 15:16. Reason: incorrect statement

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,414
    Thanks
    208
    Thanked 836 Times in 769 Posts
    Dougie,

    Year() returns an Integer not a date so trying to format it as a date doesn't work.

    Function Definition: Public Function Year(ByVal DateValue As DateTime) As Integer

    Format(Year(Now())+1,"####") works just fine however.
    or for a 2 digit year in this century: Format((Year(Now()+1) Mod 100),"##") HTH
    Last edited by RetiredGeek; 2013-07-28 at 16:24.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    DougieW (2013-07-29)

  4. #3
    Lounger
    Join Date
    Feb 2003
    Location
    Renfrewshire, Scotland
    Posts
    34
    Thanks
    2
    Thanked 1 Time in 1 Post
    from one retiredgeek to another - sometimes the most obvious things are the hardest to see. Although I had been using that code since 2009, I realised that it was only this year that particular line came into play so the problem was there all the time. I'll now check the rest of the project for similar cockups and correct them.
    Thanks very much

    Dougie

    If Now < CDate(AGMDate) And Right(QualSess, 2) > Format(Now, "yy") Then
    'Check previous Session
    QualSess = "Capn" & Right(Year(Now) - 1, 2) & Format(Now, "yy") & "_"
    Else
    ' QualSess = "Capn" & Format(Now, "yy") & Format(Year(Now) + 1, "yy") & "_"
    QualSess = "Capn" & Format(Now, "yy") & Right(CStr(Year(Now) + 1), 2) & "_"
    End If

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •