473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Setting Query criteria from a record/field

2
Hello all, hopefully you will kind enough to offer some assistance....

I want to make what i believe could be quite a complex query, something beyond the 'basic' access queries. I'm not afraid of VB coding (or programming in general), alas my knowledge of VB syntax is poor so this job is a little beyond my skills at present. But I want to learn.....


Anyway, the exact problem.

For each record in a table (called Maindata) I want to search within a text field (called Objectdescription) and if the field contains any of a list of keywords, update another field (called Cat1) to "X"

That is, I want to flag the Cat1 field with an "X" if the Objectdescription field contains a "keyword" string within the body of text.

Obviously, this is easy enough to do with a basic update query....

My difficulty comes from the keyword.

I have another table (called Keywords) where a list of keywords (in the field Keyw) are stored.

Rather than manually entering each keyword in the query and running it, I want my query to get a keyword with which to test from the Keyw field.

It would be nice if the query then looked up the next keyword and repeated....

My question really boils down to how do I get my query to automatically grab a 'criteria' from my Keywords table?

Many thanks if anyone can assist in this.....
Mar 14 '08 #1
2 2137
Stewart Ross
2,545 Expert Mod 2GB
Hi. This double-loop VB code processes the keyword file for each entry in the maindata table and updates the Cat1 field if matched. Place the code within a public code module and then call the sub from a command button's on-click event or similar.

As the code uses DAO recordsets you may need to add a reference to the MS DAO object library in your project references. From the VB editor select Tools, References and tick the MS DAO x.x object library to select it. It has been tested on a small dataset and works as expected.

Thanks for providing such a clear explanation of your requirements!

-Stewart
Expand|Select|Wrap|Line Numbers
  1. Public Sub UpdateKeywords()
  2. Dim KeywordRst as DAO.Recordset
  3. Dim DataRst as DAO.Recordset
  4. dim Textfield as String
  5. Dim KeyWord as String
  6. set DataRst = CurrentDB.OpenRecordset("MainData")
  7. set KeywordRst = CurrentDB.OpenRecordSet("KeyWords")
  8. Do While not DataRst.EOF
  9.  Textfield = DataRst![ObjectDescription]
  10.  KeyWordRst.MoveFirst
  11.  Do While not KeywordRst.EOF
  12.   KeyWord = KeywordRst![Keyw]
  13.   If Instr(TextField, KeyWord) then
  14.    DataRst.Edit
  15.    DataRst![Cat1] = "X"
  16.    DataRst.Update
  17.   end if
  18.   KeywordRst.Movenext
  19.  Loop
  20.  DataRst.Movenext
  21. Loop
  22. DataRst.Close
  23. KeywordRst.Close
  24. End Sub
  25.  
Mar 14 '08 #2
willyc
2
Many thanks for your reply.

Works a treat!
Mar 28 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
1
by: KLAU | last post by:
I have a field that retrieves information from an expression in a query. I have used a DLookup function to get the calculated field from the query. However, the relationship is 1-to-many so one...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
1
by: Michael Israel | last post by:
I am new to Access. I have a form with a single record. The keyed field is PropID (number). I want to run a query from the form that will have the current value of PropID be the variable in the...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: oh patty | last post by:
I have a query that finds results that meet any 1 of 3 criteria. It is possible for each record to meet 0, 1, 2, or all 3 of the criteria. When I run the query, each record will show up once for...
11
by: Zlatko Matić | last post by:
Hello. I have a MS Access front-end working with PostgreSQL database. I have successfully created saved File DSN. My paa-through queries are referring to that file as well as linked tables. But I...
7
by: John | last post by:
hi, i have created a search form, and i want to search for a specific item in a field. e.g. i have a field called colour, which has record1 = 'red, blue, green' and another record2 = 'red' ...
8
by: Sid | last post by:
I hope someone could help me with this. I am trying to setup a criteria to decide when to allow/not allow user to click on the check box. logically it looks simple but I am not able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.