Solved

#Error in query, Date

Posted on 2015-01-09
4
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

742 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