Solved

#Error in query, Date

Posted on 2015-01-09
4
157 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now