Answered Access Query

a5m0d1

Member
Joined
Mar 14, 2010
Messages
15
Programming Experience
1-3
I am trying to query an access database programaticly
the database is in office 2003

I want to show results for any records that are between two dates and DO NOT have Old in the distinguishedName colum. I need wild cards at both sides of *old*

In VB it removes only one record where Old is in distinguishedName and then shows the rest

Access query which works
VB.NET:
SELECT tblComputers.distinguishedName, *
FROM tblComputers
WHERE (((tblComputers.distinguishedName) Not Like "*Old Computers*") AND ((tblComputers.Last_Logon) Between #1/1/1601# And #12/12/2009#));

In VB I have tried
VB.NET:
"SELECT * FROM tblComputers WHERE distinguishedName Not Like '*Old*' and [Last_Logon] BETWEEN #01/01/1601# and #12/12/2009#"
VB.NET:
SELECT * FROM tblComputers WHERE (((tblComputers.distinguishedName) Not Like '*Old*') AND ((tblComputers.Last_Logon) Between #1/1/1601# And #12/12/2009#));

Does anyone know why?
Thanks in advance
 
Last edited:
VB.NET:
WHERE distinguishedName NOT LIKE 'DC=com1, DC=Old Computers, DC=fgfhfghfhfgh'"

This works but I want to get rid of all records that end in Old
"DC=Old Computers, DC=fgfhfghfhfgh"

All I read online says that * is a wildcard that will work for this, I can have a paragraph before it and it will pick it out.

This works in access but cant get it right in VB

ALL I need is to know the right way to use the wild card.

it shud be this, but it doesnt work. I am sure its simple



VB.NET:
WHERE distinguishedName NOT LIKE '*DC=Old Computers, DC=fgfhfghfhfgh'"

Hope that makes it more clear
Thanks
 
One other thing I can get these to work on there own but how do I get them to work together?

WHERE [Last_Logon] BETWEEN #01/01/1601# and #12/12/2009#

and

WHERE distinguishedName NOT LIKE '%old%'
 
Unless you are doing a sub SELECT you can't have two WHERE clauses...

You can, however, have a WHERE clause with an AND clause but that would mean that you are looking for records that meet both criteria.

You could subtitutue the AND clause for an OR clause.

Try them both out and see which meets your needs.
 
Back
Top