Results 1 to 6 of 6
  1. #1
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83

    Finding a field from last month to put in new month


    In a query, or maybe it can be done in VB, how do I search for a record from last month. There is a date field in each record, and the primary key is the name of the employee AND the month. I am trying to carry over a number field from last month to the new month data for that employee and I can accomplish this in excel using the edate function but I cannot figure this out in access as I am migrating my data to access. I am familiar with SQL.

    Thanks

  2. #2
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Create a calculated field like:

    Code:
    Recordmonth: Month([YourMonthField])
    then put on criteria like:

    Code:
    =Month(Now())-1
    Cheers,

  3. #3
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    Hm, I would think this would work but it is going back one year, not one month. My date field (not the calculated one) is setup like 10/1/2010, and the calculation field is bring back 10. I will try to look into this as well, but any ideas?

  4. #4
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    actually sorry it went back one month AND one month and one year. Is there a way to do this on one field without dividing the date field into a month column and year column? (e.g. in your criteria introduce AND to get -1 and the year now(), even though this will come back to bite me when the new year switches over)

  5. #5
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    If you have more than one years worth of records in your data, then use this as your calculated field:

    Code:
    RecordMonth: Year([YourDateField]) & " " & Month([YourDateField])
    and this as criteria:

    Code:
    =IIf(Month(Now())=1,Year(Now())-1,Year(Now())) & " " & IIf(Month(Now())=1,12,Month(Now())-1)

  6. #6
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    works! thanks. I tried something similar but was using the "AND" instead of "&" and the query was returning nothing. But now it is good.

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

Similar Threads

  1. How to group by month
    By okrobie in forum Queries
    Replies: 4
    Last Post: 06-09-2011, 04:41 AM
  2. First Weds of Month...
    By dweekley in forum Queries
    Replies: 5
    Last Post: 05-17-2010, 12:04 AM
  3. month function..
    By thewabit in forum Programming
    Replies: 13
    Last Post: 04-19-2010, 10:01 PM
  4. Current month in a field as default
    By leandrosarno in forum Access
    Replies: 6
    Last Post: 02-09-2010, 05:40 AM
  5. SQL Query by day to end of month
    By tcasey in forum Queries
    Replies: 0
    Last Post: 10-07-2008, 09:55 PM

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