Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2007, 08:43 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Want to Search Several Fields for the Same Keyword

I'm a graduate student who has used my limited knowledge of Access to construct a database to organize my notes. I've created three keyword fields that I use to code the contents of each record (1 record=1 note). I'd like to construct a query that will allow me to search all three fields for a particular keyword.

Could anyone fill me in on what the SQL would be for such a query? Again, I want a query that will yield a list of all records in which the keyword appears in any of the three fields.

 
Old March 16th, 2007, 08:48 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

This would probably be easier to do in the query window, but the SQL would look something like this:

WHERE Field1 LIKE '*' * keyword & '*' OR Field2 LIKE '*' * keyword & '*' OR Field3 LIKE '*' * keyword & '*'

If you are calling the SQL from VBA, you may need to substitute the *'s for %'s

Hope that helps

Mike

Mike
EchoVue.com
 
Old March 16th, 2007, 10:53 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks, Mike! I didn't think it was possible to do something like this in the query window. Could I trouble you to say a little more about how I'd set it up in the window (I always prefer to avoid SQL when I can)?

Again, real grateful to you.

Best,
E

 
Old March 16th, 2007, 11:08 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I'm having trouble thinking of how best to describe it, but here goes...

In access, go to the query tab, and then click "Create a new Query in design view"

THe screen you get will be divided in to, and there will be another window with all of tables listed.

Double click the tables you would like to add, and then click close when you are done.

If you need to set up joins, you can now do it by dragging one field to another, then right clicking and editing the properties to choose the type of join.

Double click any fields you want to return and they will appear down in the bottom section.

Down in the bottom section, you can now add criteria, just in the format

LIKE '*' & 'Keyword' & '*'

Put it on different lines for each field to make it an OR criteria.

Since I suspect that you may need to use SQL anyway, you can now select SQL View from the View menu, and will have the SQL nicely formatted.

There is also a way to have the query prompt you for the variable in the criteria, but I haven't done that for a long long time.

Typically I use this to build my SQL strings, and then transfer them to my code - Heck, I even use it when I need to build SQL for PHP/MySQL apps!

Yell if you need more info,

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search by Keyword Grafixx01 Access 10 May 31st, 2007 08:59 AM
Keyword search Echo10 Excel VBA 3 April 23rd, 2006 08:10 AM
Multiple Keyword Search tuffour Classic ASP Databases 3 September 10th, 2004 06:12 AM
highlighting the search keyword(s) Adam H-W Classic ASP Basics 2 February 10th, 2004 09:08 AM
XSLT keyword search help adamr415 XSLT 2 November 12th, 2003 08:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.