Solved

Find Method (ADO) need boolean criteria

Posted on 2002-06-19
10
219 Views
Last Modified: 2010-05-02
Is it possible to use a boolean expression in the criteria of the .Find method on an ADO recordset?

For instance:

rs.find "Purchaser = 'Acme' AND InvoiceNo = 'X34FF'",,adSearchForward

(this results in syntax error 3001 - argument of the wrong type blah blah blah)

I also tried:
rs.find "Purchaser & InvoiceNo = 'AcmeX34FF'",,adSearchForward

Same result..


Maybe it can't be done??
0
Comment
Question by:jeffstatt
  • 4
  • 3
  • 3
10 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7093467
when you open your recordset, you need to concatenate your purchaser and invoice number (select *, purchaser + invoiceno as NewField FROM ...) and use this field in your find( rs.find "NewField = 'AcmeX34FF'")
0
 

Author Comment

by:jeffstatt
ID: 7093478
The problem is that I am pulling the recordset directly from an XML document (I do not open it using sql) so I don't have the option of concatenating the field names.

I'm not against having the XML provider send me a concatenated field, but I'd like to exhaust this question first.
0
 
LVL 4

Expert Comment

by:gencross
ID: 7093481
Good answer emoreau.  That is the only way I know to do it also.
0
 
LVL 4

Accepted Solution

by:
gencross earned 300 total points
ID: 7093500
What about using a filter?

Instead of:
rs.find "Purchaser = 'Acme' AND InvoiceNo = 'X34FF'",,adSearchForward

use:

rs.Filter = "Purchaser = 'Acme' AND InvoiceNo = 'X34FF'"

When you are finished with the filter:

rs.Filter = adFilterNone

This will allow only the the records in the criteria to be viewed in the rs.

Hope this helps
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7093505
There is another way: use the Filter property.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7093507
You beat me!
0
 

Author Comment

by:jeffstatt
ID: 7093514
That'll work as an exceptable substitute.  I forgot completely about .Filter! DUH!

Thanks!
0
 
LVL 4

Expert Comment

by:gencross
ID: 7093538
I'm glad that solved your problem, but why the grade B?  Your question was answered correctly.

<<Is it possible to use a boolean expression in the criteria of the .Find method on an ADO recordset?

Both emoreau and myself said it couldn't be done the way you wanted it.  Then we both gave another good solution (I beat him by about five seconds:))

In the future I would think an answer like this would deserve an A :)
0
 

Author Comment

by:jeffstatt
ID: 7093544
Because the question was Can the .Find method be done with a boolean expression in the criteria

not

Is there an alternative?

Besides you got 300 points for a relatively easy answer :)
0
 

Author Comment

by:jeffstatt
ID: 7093546
How 'bout B+ ?

;)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 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

10 Experts available now in Live!

Get 1:1 Help Now