Solved

#Error in query, Date

Posted on 2015-01-09
4
165 Views
Last Modified: 2015-01-09
experts, I get a #error in the attached query.  I know the reason but I dont know how to fix.  If you delete the date in  [UltimateExpirey] then the #error goes away.  

here is the calculation:  
NotifyByDate: IIf([DateOfExpirey]<[UltimateExpirey],[DateOfExpirey]-Format(Nz([tblAutoExtend_Evergreen].[DaysNotice],0),"m/dd/yyyy"),Format([DateOfExpirey]-Nz([tblAutoExtend_Evergreen].[DaysNotice],0),"m/dd/yyyy"))

Please open attached and open the query "error".  There are 2 tables and 1 query.  

thank you.
EE.accdb
0
Comment
Question by:pdvsa
  • 2
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40541343
pdvsa,

I'm not sure what you are trying to achieve here, but the syntax of the True portions of this IIF statement are confusing.  based on the way you have this configured, you are going to subtract some date in 1900, from your DateOfExpirery as opposed to subtracting some number of days from that date.

Also, the False part is very similar to the first, although it looks like it may actually be formatted properly.  I'm not sure what the purpose of UltimateExpirey is in the IIF statement it it doesn't have a role in the subsequent calculations.

If you could explain what you are trying to do rather than display the code that isn't working, it would be helpful.

I would recommend you write a function which will give you the ability to pass in the various parameters and properly test for NULLs.  This is one of my pet peeves, I detest writing long equations in queries because they cannot be documented and someone who comes along behind me to maintain my code will have no idea what I'm trying to accomplish.  I always put business logic like this in function calls so that I can add remarks and appropriately test for values in the code.

It might look something like:

Public Function fnNotifyByDate(ExpireDate as Variant, UltimateExpire as Variant, _
                                                         DaysNotice as integer) as Variant

    If isNull(ExpireDate) Then
        fnNotifyByDate = NULL
    ElseIf isnull(UltimateExpire) Then
        fnNotifyByDate = NULL
    Elseif ExpireDate < UltimateExpire Then
        fnNotifyByDate =Format(DateAdd("d", -NZ(DaysNotice, 0), ExpireDate), "m/dd/yyyy")
    Else
        fnNotifyByDate =Format(DateAdd("d", -NZ(DaysNotice, 0), UltimateExpire), "m/dd/yyyy")
    End If

End Function

Open in new window

Then you would simply call this function in your query:

NotifyByDate: fnNotifyByDate(([DateOfExpirey], [UltimateExpirey], [DaysNotice])
0
 

Author Closing Comment

by:pdvsa
ID: 40541360
that was amazing.  It worked.  Thanks for that tip to make a function.   It makes a lot of sense.   Leaving the office on a good note!  have a good weekend.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40541373
pdvsa,

Make sure that logic is correct!  It is not configured exactly like your IIF() statement was.

Have a good weekend.

Dale
0
 

Author Comment

by:pdvsa
ID: 40541552
Fyed, yes, I discovered I had to tweak it just a bit.  It works great!  Thank you
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

832 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