Solved

DateAdd Function ????

Posted on 2006-07-03
2
446 Views
Last Modified: 2006-11-18
I have a field on a form called [currentperiod] and it holds a number from 1-12 dependant on the month of the year a report is running for. I need to be able to subtract 1 or 2 from this number to be able to produce comaprison monthly reports.

ie:

If I'm running a report for period 10, I need to be able to do periods 8 & 9 also not a problem as I can just subtract one. however when I reach period 1 next year I need to be able to have the reports generated for periods 11 & 12 of the prior year. I have tried dateadd("m",-1,[currentperiod]) but it does not work all the time.

Is there anything I can do?
0
Comment
Question by:Carl2002
2 Comments
 
LVL 14

Assisted Solution

by:bluelizard
bluelizard earned 200 total points
ID: 17029519
instead of using these formulae

  =[currentperiod] - 1
and
  =[currentperiod] - 2

use these

  =iif([currentperiod]>1;([currentperiod] - 1);([currentperiod] + 11 ))
and
  =iif([currentperiod]>2;([currentperiod] - 2);([currentperiod] + 10 ))


--bluelizard
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 300 total points
ID: 17029528
Is currentperiod a date - or is it a number from 1 to 12?

It doese not look like it is a date,

I would use the logic

MonthsBeforeTime = (([currentperiod] + 12 - monthsPrior - 1) Mod 12) + 1

Where monthsPrior is the number of months.

This will effectively treat the numbers as "wrapping" around the number 12
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

707 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

12 Experts available now in Live!

Get 1:1 Help Now