?
SolvedPrivate

How can I code access 2010 vba to search all data tables for keywords

Posted on 2014-08-19
5
Medium Priority
?
38 Views
Last Modified: 2016-02-11
Need to modify code below to be able to search entire database for term in table tblSearchTerm.Term field.  


dim tbl as tabledef
dim fld as field
dim rs as recordset
for each tbl in dbEngine(0)(0).tabledefs
  for each fld in tbl.fields
    set rs = dbEngine(0)(0).OpenRecordset("Select " & fld.name & " from " & tbl.name & " Inner Join tblSearchTerms On " & fld.name & "=tblSearchTerms.Term")
    if rs.EOF then
    else
        debug.print "keywords found in table: " & tbl.name & " field: " & fld.name
    end if
  next
next
0
Comment
Question by:conardb
  • 2
  • 2
4 Comments
 
LVL 85
ID: 40270918
Perhaps something like:

dim tbl as tabledef
dim fld as field
dim rs as recordset
for each tbl in dbEngine(0)(0).tabledefs
  for each fld in tbl.fields
    set rs = dbEngine(0)(0).OpenRecordset("SELECT * FROM " & tbl.name & " WHERE " & fld.Name & " IN  (SELECT * FROM tblSearchTerms)")
    if rs.EOF then
    else
        debug.print "keywords found in table: " & tbl.name & " field: " & fld.name
    end if
  next
next
0
 

Author Comment

by:conardb
ID: 40270928
getting type mismatch using below:

                strSQL = "SELECT * FROM " & tbl.Name & " WHERE " & fld.Name & " IN  (SELECT * FROM tblSearchTerms)"
                Set rs = DBEngine(0)(0).OpenRecordset(strSQL)
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1500 total points
ID: 40272259
If "fld" is a Numeric field, then you can't use the IN syntax - but then you're searching for Keywords, which would exclude numeric values, so just check the fld.Type:

If fld.Type = dbText or fld.Type = dbMemo Then
  '/ create the sql here
End If
0
 

Author Comment

by:conardb
ID: 40272310
thanks... getting "block variable not set" on if rs.eof
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

862 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