Solved

#Error in query, Date

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…

932 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