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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql to retreive date

Status
Not open for further replies.

MONFU

Programmer
Oct 27, 2001
35
MT
Dear all,

I am trying to retreive data from an Access table, depending on the dates chosen by the user. I have 2 list boxes, NewsMonth and NewsYear, and the results are numbers, for example for NewsMonth, June is 6 and for the year it is 2003. Then I am trying to create the sql to retrieve the correct data but I am getting a syntax error. Can you please help?

THis is my sql:-
'*** Create the sql to retreive the main sections from the table
sqlNews = "SELECT * FROM newsArticles "
sqlNews=sqlNews & " WHERE (month(newsDate)) = #" & NewsMonth & "#"
sqlNews=sqlNews & " AND (Year(newsDate)) = #" & NewsYear & "#"
sqlNews=sqlNews & " ORDER BY NewsDate Desc"

Thanks for your help and time
 
Your syntax is slightly incorrect. When referring to dates in JetSQL you do indeed need to put # signs around them, but in your case you're not actually referring to dates. You stated that NewsMonth and NewsYear are both numbers, so the # signs are inappropriate. Simply remove them:
Code:
sqlNews = "SELECT * FROM newsArticles"
sqlNews=sqlNews & " WHERE (month(newsDate)) = " & NewsMonth
sqlNews=sqlNews & " AND (Year(newsDate)) = " & NewsYear
sqlNews=sqlNews & " ORDER BY NewsDate Desc"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top