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

Anyone know what could be wrong with.....

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
....this SQL statement?

SELECT * FROM tblMainRepos WHERE DateAdded = " & CDate(tvTreeView.SelectedItem.Text)

Where DataAdded is a short date format field in an Access database and tvTreeView.SelectedItem.Text is a short date string?

It doesn't give an error, it just doesn't return any records when I know it should!

Many thanks,

elziko
 
Hi,

Try an surround your date with '#':

----------------------------------------------------------
SELECT * FROM tblMainRepos WHERE DateAdded = #" & CDate(tvTreeView.SelectedItem.Text) & "#"
----------------------------------------------------------

Sunaj

 
Where do you have your code? If you have it in the TreeView click event, I would suggest moving it to the TreeView NodeClick event.
 
Access needs the date between # so try:

SELECT * FROM tblMainRepos WHERE DateAdded = #" & CDate(tvTreeView.SelectedItem.Text) & "#"

Hope this helps
 
Is your windows settings set to the US date style??
I had the problem because the Duthc datestyle is dd-mm-yyyy in an SQL statement this gives different records than expected (mostly no records) instead of an error.
you could try this as a sql statement:
SELECT * FROM tblMainRepos WHERE DateAdded = #" & Format(CDate(tvTreeView.SelectedItem.Text), "mm/dd/yyyy") & "#"

note that the date is inclosed in ## this might allso be the cause of your problems (now the ## are missing).
 
# did it nicely.

Thanks a lot,

elziko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top