Make Table with year

Posted on 2012-09-02
Last Modified: 2012-09-02
I have a Maketable query which I would run each year,

SELECT tblShiptProd.* INTO tblShipt2011
FROM tblShiptProd
WHERE (((Year([ShipDate]))=Year(Date())-1));

I could run this in a procedure on a form, if I knew how to update the year part of the table name.
I'm sure there is a way of making a table with this query and naming the table at runtime with the previous year. i.e. If I run the procedure in January 2013 the table it would make would be called tblShipt2012.

As usual any advice is much appreciated.
Question by:Stephen Byrom
    LVL 61

    Accepted Solution

    You could do this using VBA in a command button click event:

    Dim strSQL as string
    Dim strTableName as string
    strTableName = tblShipt & (Year(Date()) - 1)
    strSQL = "SELECT tblShiptProd.* INTO " & strTableName & "FROM tblShiptProd WHERE (((Year([ShipDate]))=Year(Date())-1));"
    CurrentDB.execute strSQL, dbfailonerror

    Open in new window

    LVL 1

    Author Closing Comment

    by:Stephen Byrom

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now