Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query too complex .....

Status
Not open for further replies.

DaJoin

Technical User
Sep 15, 2002
9
BE
I'm haveing a table with a birthday, stored as 12.11 for the 12th of november .
I'm trying to make a query, to select only records with a birthday between dates d1 and d2, but Access always tells me that the query is too complex to evaluate.

Sometimes, I succeed in retrieving the query, but when I then close and reopen access, again, the query is too complex.

Can anyone advise me on how to solve this ?

This is my query :

SELECT * FROM addresses
WHERE (((CDate(d1))<=DateSerial(Year(Now()),Val(Mid$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)+1)),Val(Left$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)-1)))) And ((DateSerial(Year(Now()),Val(Mid$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)+1)),Val(Left$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)-1))))<=CDate(d2))) Or (((CDate(d1))<=DateSerial(Year(Now())+1,Val(Mid$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)+1)),Val(Left$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)-1)))) And ((DateSerial(Year(Now())+1,Val(Mid$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)+1)),Val(Left$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)-1))))<=CDate([Forms]![members]![d2])))


(Get the day and month out of the birthday, and compare if this years birthday between d1 and d2, or if next years birthday between d1 and d2)
 

Try to divide it to rows in same variable like:

strSql= &quot; SELECT * FROM addresses
WHERE (((CDate(d1))<=DateSerial(Year(Now()),Val(Mid$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)+1)),Val(Left$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)-1)))) &quot;

strSql= strSql & &quot;And ((DateSerial(Year(Now()),Val(Mid$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)+1)),Val(Left$([addresses].[birthday],InStr([addresses].[birthday],&quot;.&quot;)-1))))<=CDate(d2)))&quot;


and so on
good luck


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top