Results 1 to 15 of 15
  1. #1
    Join Date
    Mar 2005
    Posts
    12

    Unanswered: Problem with Year Function

    I am developing an application in Access 2002. I am having a problem with the Year function. The code that I am using:

    xc = Year(Date)

    Simple stuff, but I am getting a runtime 438 error when it hits that line stating that object doesn't support property or method. When I debug it, Date has the proper date in it, but when I roll over the Year function it shows the object doesn't support property or method error message.

    Any ideas? Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    You can try the following: datepart("yyyy",date()) which does the same thing. Make sure the variable xc is set to an integer
    Justin

  3. #3
    Join Date
    Mar 2005
    Posts
    14

    Wink

    Can you show some more of the supporting code please.
    Also, is the year being stored in a field and what event are you using.

    Thanks.

  4. #4
    Join Date
    Mar 2005
    Posts
    12
    I actually simplified the code while trying to debug it. The true code is:

    Private Sub Year_Click()
    'Sets the Date From and Date To text boxes
    'to show complete current year

    Me!date_from = CDate("01/01/" & Year(Date))
    Me!date_to = DateAdd("d", -1, DateAdd("yyyy", 1, Me!date_from))

    End Sub

    Hope this helps!

  5. #5
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    Try the code without the cdate command.

  6. #6
    Join Date
    Mar 2005
    Posts
    12
    It may also help to know if am getting thesame problem with the Year and Month functions on this line:

    Me!date_from = CDate("01/" & Month(Date) & "/" & Year(Date))

  7. #7
    Join Date
    Mar 2005
    Posts
    12
    Justin,

    I have tried the command just as:

    xc = Year(Date)

    with the same results. Seems like I am missing a reference in the code module or something????

  8. #8
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    I always use date serial i.e in your case

    dateserial(year(now),01,01)

  9. #9
    Join Date
    Mar 2005
    Posts
    12
    The datepart command that Justin suggests above works, but I am still at a lose why YEAR and MONTH do not work?

  10. #10
    Join Date
    Mar 2005
    Posts
    12
    David,

    The Year function still will not work in your date serial option.

  11. #11
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926

    Year

    Just a thought but there's probably something better others can offer. How about:

    xc = Format(Date(),"yyyy")
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  12. #12
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    It may well be that Access has not been installed correctly - if your IT department have installed it they probably installed the basic configuration rather then the full version with all the add-ons and wizards. your version of access maybe missing a reference in order to use the Year function.

    As a test, in your debug window type the following:

    ? year(date())

    and see if you get the same error message.

    Justin

  13. #13
    Join Date
    Mar 2005
    Posts
    12
    Justin,

    I tried the code in the immediate window with the same results. I have fixed the program by using your datepart suggestion for year and month. That works along with the DateAdd function. I would still like to figure out why year and month don't work.

    The references that are checked are:

    Visual Basic for Applications
    Microsoft Access 10.0 Object Library
    OLE Automation
    Microsoft ActiveX Data Objects 2.1 Library
    Microsoft Calenadar Control 8.0

  14. #14
    Join Date
    Mar 2005
    Posts
    12
    I fixed it. I took the Microsoft Calendar Control 8.0 reference out and the year function works now. Thanks for everyone's input.

  15. #15
    Join Date
    Nov 2003
    Location
    LONDON
    Posts
    238
    That would make sense. The calendar control has a year function as well as VBA, so when you use the function Access doesn't know which one you are referring to.

    If you used VBA.Year(Date()) you will probably find that it will work
    Justin

Posting Permissions

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