469,887 Members | 1,958 Online

# Problem with calculated results

I am using this calculation in a query to find invoices that are less then
30 days, over 30, over 60, over 90, and over 120.

IIf((Now()-AR6_OpenInvoice1.INV_DATE)\30>4,4,(Now()-AR6_OpenInvoice1.INV_DAT
E)\30);
The problem is the invoice was created on let say 9/17/03 and is less then
30 days old but the calculation looks at it and says it is over 30. What do
I need to fix this problem?

Thanks agin for all the help!!

Greg
Nov 12 '05 #1
1 1394
It's quite possible, using Now() that, depending upon the Inv_Date and the
exact time of day the query was run, you may miss what you think should be
there. In other words, if you run the query at 8 AM, you may return more (or
fewer) records than if you run the query at 11 PM.

Now() carries a time of day value as well as the date.
Unless you are looking for records exactly 30 days to the second of when the
query is run, use Date() instead.

Also, unless the query has more than one table with the same Field Name
(Inv_Date), you don't need the table name qualifier.
If the logic of your expression is correct, try:

IIf((Date() - [INV_DATE])\30>4,4,(Date() - [INV_DATE])\30)

Or... why not make a new Module:

Function InvoiceAge(DateIn as Date)
Dim intElapsedDays as integer
Dim intResult as integer
intElapsedDays = DateDiff("d",DateIn,Date())

Select Case intElapsedDays
Case 1 to 29
intResult = 1
Case 30 to 59
intResult = 30
Case 60 to 89
intResult = 60
Case 90 to 119
untResult = 90
Case Else
intResult = 120
End Select
InvoiceAge = intResult
End Function
===============
Change the time periods and the expected results to suit yourself.
Call the function from a query:
Aged: InvoiceAge([Inv_Date])
Sort by this field.

--
Fred

I do not reply to personal e-mail.
"Greg" <gk******@itlan.net> wrote in message
I am using this calculation in a query to find invoices that are less then
30 days, over 30, over 60, over 90, and over 120.

IIf((Now()-AR6_OpenInvoice1.INV_DATE)\30>4,4,(Now()-AR6_OpenInvoice1.INV_DAT E)\30);
The problem is the invoice was created on let say 9/17/03 and is less then
30 days old but the calculation looks at it and says it is over 30. What do I need to fix this problem?

Thanks agin for all the help!!

Greg

Nov 12 '05 #2

### This discussion thread is closed

Replies have been disabled for this discussion.