Results 1 to 10 of 10
  1. #1
    83dons is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    15

    Searching for a particular ID number across all tables in an Access Database


    I have inherited an old Access database with about 300 tables. We need to be able to search for a client ID number (for example 'R12345') in every table in the database and to return all tables that it exists in (all rows would actually be good but a list of the tables it exists in would do as a summary). So I guess the query would need to go through every column and every row in every table in the database before returning its results. I am guessing this must be possible but haven't the faintest idea what SQL would achieve this! Can anyone help? It is important we find every entry that references this client ID in the database as otherwise medical records for that person could be missed out of the search.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742

  3. #3
    83dons is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    15
    Hi that is not exactly what I am requiring. I require all columns and all rows of every table to be searched for the ID number.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Hmmm? Did you read post #4 on the link I provided?

    Perhaps you can describe the details of
    Hi that is not exactly what I am requiring
    ?

  5. #5
    83dons is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    15
    I already have see the first post...

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    To get around the primary key restraint in the above link, I think you'd need to
    - iterate over the db tables collection in an outer loop, ignoring the system tables
    - iterate over the fields collection of a table in an inner loop, and execute a simple sql search on a field
    - move to the next field and search again until you find a result
    - store the 'active' table name and field, and if it seems reasonable, the value in the first field (in case it's an index that can aid in finding the record row)
    - exit the inner loop, and move to the next table in the outer loop
    - rinse and repeat
    - present the results as a report from wherever the values were stored (table would be simplest)

    Perhaps you will get a better response here, or if you search the 'net yourself, you might find someone who's already done this. Or maybe Orange's db could be easily adapted to not require that the tables have a PK field? Failing that, I've sketched out the basic steps I think you'd have to find code for.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    I mocked up 2 tables and tried the universal search.

    I guess I'm missing something.

    Click image for larger version. 

Name:	83dons.png 
Views:	14 
Size:	60.5 KB 
ID:	33956


    Micron, where did you see anything in the OP's info that the PK is an issue?

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,818
    Ya know, I think that stuck in my head after reading at the other thread. Sorry.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    No, I also thought the OP was commenting on either PK or limited to "text".
    The routine works with text and memo fields, so I questioned the 'R12345' .

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-19-2015, 09:00 AM
  2. Replies: 2
    Last Post: 01-14-2013, 11:27 PM
  3. Searching a whole Access Database
    By mejia.j88 in forum Access
    Replies: 2
    Last Post: 04-24-2012, 03:42 PM
  4. Searching Multiple Tables
    By Don Webb in forum Forms
    Replies: 3
    Last Post: 01-19-2012, 08:40 PM
  5. Searching mutiple tables
    By mbolster in forum Access
    Replies: 8
    Last Post: 07-06-2010, 10:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums