[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

#Error in query, Date

Posted on 2015-01-09
4
Medium Priority
?
176 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 48

Accepted Solution

by:
Dale Fye earned 2000 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 48

Expert Comment

by:Dale Fye
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

649 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