Solved

problem with Filter property in ADO......?

Posted on 2006-07-16
8
319 Views
Last Modified: 2008-02-01
hi
iwant to filter my data depend on date and cunsumerFamily in the following way:
for example                     month=2 AND cunsumerFamily=X
 another example             year=1985 AND  cunsumerFamily=X
but i dont know how to write a sql statement for ADO filter property that contained both date and consumerFamily with conditions above.
any help will be appreciated
thanks bayat
vb6
ado datacontrol
access 2000 database
0
Comment
Question by:sdf145
  • 3
  • 3
  • 2
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17119897
well u could do one of two ways

Actually specify this in your sql
e.g.

sSql = "SELECT * FROM Table Where Month=2 AND CunsumerFamily='X'"

then use this sql when u open the recordset

or use the recordset filter

rs.Find "Month=2 AND CunsumerFamily='X'"

0
 
LVL 44

Expert Comment

by:bruintje
ID: 17119899
Hi sdf145,
----------

did you try

rst.Filter = "Month=2 And ConsumerFamily <> 'X'"

----------
bruintje
share what you know, learn what you don't
0
 

Author Comment

by:sdf145
ID: 17119991
it is not answer i am looking for
date field in database is in this format YYYY/MM/DD
but im looking for YYYY or MM
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 70 total points
ID: 17120008
try this then

Year(<datefld>)
or
Month(<datefld>)


Use can also use Format or Datepart I think

Format(<datefld>,"YYYY")

Datepart("yyyy",<datefld>)

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 44

Assisted Solution

by:bruintje
bruintje earned 30 total points
ID: 17120020
rst.Filter = "MONTH(MyDate)=2 And ConsumerFamily <> 'X'"
OR
rst.Filter = "YEAR(MyDate)=1998 And ConsumerFamily <> 'X'"

but i'm not sure if you can do that in a ado filter

else you would need to do it in the SQL select statement
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17120022
:)
0
 

Author Comment

by:sdf145
ID: 17120053
thank u for ur attempt
u are perfect
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17126984
glad your sorted and thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now