Code:
Select Case strOfferMonth
case "1"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 1 AND DatePart('m',OfferEnds) => 1 ORDER BY SiteCode ASC;"
case "2"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 2 AND DatePart('m',OfferEnds) => 2 ORDER BY SiteCode ASC;"
case "3"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 3 AND DatePart('m',OfferEnds) => 3 ORDER BY SiteCode ASC;"
case "4"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 4 AND DatePart('m',OfferEnds) => 4 ORDER BY SiteCode ASC;"
case "5"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 5 AND DatePart('m',OfferEnds) => 5 ORDER BY SiteCode ASC;"
case "6"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 6 AND DatePart('m',OfferEnds) => 6 ORDER BY SiteCode ASC;"
case "7"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 7 AND DatePart('m',OfferEnds) => 7 ORDER BY SiteCode ASC;"
case "8"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 8 AND DatePart('m',OfferEnds) => 8 ORDER BY SiteCode ASC;"
case "9"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 9 AND DatePart('m',OfferEnds) => 9 ORDER BY SiteCode ASC;"
case "10"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 10 AND DatePart('m',OfferEnds) => 10 ORDER BY SiteCode ASC;"
case "11"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 11 AND DatePart('m',OfferEnds) => 11 ORDER BY SiteCode ASC;"
case "12"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 12 AND DatePart('m',OfferEnds) => 12 ORDER BY SiteCode ASC;"
case Else
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= DatePart('m',Now) AND DatePart('m',OfferEnds) => DatePart('m',Now) ORDER BY SiteCode ASC;"
End Select
Produces the error:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression 'DatePart('m',OfferBegins) <= 1 AND WHERE DatePart('m',OfferEnds) => 1'.
Where as
Code:
Select Case strOfferMonth
case "1"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 1 ORDER BY SiteCode ASC;"
case "2"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 2 ORDER BY SiteCode ASC;"
case "3"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 3 ORDER BY SiteCode ASC;"
case "4"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 4 ORDER BY SiteCode ASC;"
case "5"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 5 ORDER BY SiteCode ASC;"
case "6"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 6 ORDER BY SiteCode ASC;"
case "7"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 7 ORDER BY SiteCode ASC;"
case "8"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 8 ORDER BY SiteCode ASC;"
case "9"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 9 ORDER BY SiteCode ASC;"
case "10"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 10 ORDER BY SiteCode ASC;"
case "11"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 11 ORDER BY SiteCode ASC;"
case "12"
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= 12 ORDER BY SiteCode ASC;"
case Else
strSQL = "SELECT * from Offers WHERE DatePart('m',OfferBegins) <= DatePart('m',Now) ORDER BY SiteCode ASC;"
End Select
Is absolutely fine!
Any ideas peeps?