473,396 Members | 2,139 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.

Skipping over Linked tables

Hi. I have written a script that searches through every field in every table in a given database. It works fine in most databases, however, when I run it in a database with Linked tables, the script crashes when it reaches a Linked table and tried to search through it.

My code is written below.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Sub MK5Search()
  4. GenerateFieldSizeInfo
  5. End Sub
  6.  
  7. Sub GenerateFieldSizeInfo()
  8.     Dim cdb As DAO.Database
  9.     Dim oTable As DAO.TableDef
  10.     Dim oField As DAO.Field
  11.     Dim rsTable As DAO.Recordset
  12.     Dim strSQLTable As String
  13.     Dim iMaxSize As Integer
  14.     Dim iHeadroom As Integer
  15.     Dim iFileNumber As Integer
  16.     Dim strOutputFile As String
  17.  
  18.     'Create the header file. (If the file already exists, its contents are overwritten.)
  19.     iFileNumber = 1
  20.     'Enter the location you want the word file to be exported in the quotes below
  21.     strOutputFile = "C:\etc.."
  22.  
  23.     Open strOutputFile For Output As #iFileNumber
  24.     'Open the database.
  25.     Set cdb = CurrentDb
  26.  
  27.     Print #iFileNumber, "Rec Num "; Tab(15); " Table"; Tab(55); "Field"; Tab(85); "Relevant Text"; Tab(110);
  28.     Print #iFileNumber, String(118, "-")
  29.  
  30. 'If oField.Properties("Type").Value <> "Linked Access" Then
  31. For Each oTable In CurrentDb.TableDefs
  32.   If Not oTable.Name Like "MSys*" Or Not oTable.Name Like "MSys*" Then    'ignore System Tables
  33.     Set rsTable = cdb.OpenRecordset(oTable.Name, dbOpenDynaset)
  34.       intNumOfFields = rsTable.Fields.Count
  35.         For intCounter = 0 To intNumOfFields - 1
  36.           Do While Not rsTable.EOF
  37.             If InStr(rsTable.Fields(intCounter).Value, strSearchString) > 0 Then
  38.                Print #iFileNumber, rsTable.AbsolutePosition + 1; Tab(16); _
  39.                   oTable.Name; Tab(55); _
  40.                   rsTable.Fields(intCounter).Name; Tab(85); _
  41.                   rsTable.Fields(intCounter).Value
  42.             End If
  43.  
  44.             rsTable.MoveNext
  45.           Loop
  46.           rsTable.MoveFirst
  47.         Next
  48.   End If
  49. Next
  50. 'End If
  51.  
  52. Close #iFileNumber
  53. End Sub
  54.  
  55.  
  56. Public Function fSearchForString(strSearchString) As Boolean
  57. On Error GoTo Err_fSearchForString
  58.  
  59. If strSearchString("*MK 5*") Then
  60.   MsgBox "Search  for String a success!", vbExclamation, "Success"
  61. Else
  62.   MsgBox "What in the world have you done, ADezii!", vbCritical, "Failure"
  63. End If
  64.  
  65. Exit_fSearchForString:
  66.   Exit Function
  67.  
  68. Err_fSearchForString:
  69.   fSearchForString = False
  70.   MsgBox Err.Description, vbExclamation, "Error in fSearchForString()"
  71.   DoCmd.Hourglass False
  72.   If Not MyRS Is Nothing Then
  73.     MyRS.Close
  74.     Set MyRS = Nothing
  75.   End If
  76.     Resume Exit_fSearchForString
  77.  
  78. End Function
  79.  
Line 30 is where I attempted to pass over the linked tables, but it doesn't work. That is why I commented the IF statement out.

If anyone has any recommendations or has done this before, please let me know. I feel that my error is in identifying a Linked table properly; there is no clear explanation in Help that I could find.

Thanks for you help as usual!

Ian
Jul 24 '08 #1
3 2284
Stewart Ross
2,545 Expert Mod 2GB
Hi. If you want to identify a linked table look at the tabledef's Connect property, which will be null for tables that are not linked, and contain the connection path/connection string for tables that are linked.

At line 32 you could add

Expand|Select|Wrap|Line Numbers
  1. ... OR NOT Isnull(oTable.Connect) then ' ignore system tables and linked tables

-Stewart
Jul 28 '08 #2
Hi. Thanks for the help, however, the script seems to ignore any form of that code. I am not quite sure why. Any suggestions?
Jul 28 '08 #3
ADezii
8,834 Expert 8TB
You can check the length of the Connect String for the individual TableDef Objects, a Linked Table will have a value > 0 and a Local Table will have a value of 0. This logic can be incorporated into your existing code and optionally shorten the syntax if so desired:
Expand|Select|Wrap|Line Numbers
  1. 'Not MSys* or USys* and Not a Linked Table
  2. If (Not oTable.Name Like "MSys*" Or Not oTable.Name Like "USys*") And Len(oTable.Connect) = 0 Then
  3.                                  OR
  4. 'More restrictive
  5. If (Not oTable.Name Like "?Sys*") And (Len(oTable.Connect) = 0) Then
  6.  
Jul 28 '08 #4

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

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
5
by: pinballjim | last post by:
Hello everyone, I'm looking for a simple way to create a local copy of a linked table. I've got a database that links about 10 tables from other databases. This works fine on my machine, but I...
2
by: Internet Arrow Limited | last post by:
Hi, I have a requirement to write an access application that must run under access97 and access2K. Some users will use Acess2K to access data that will also be accessed by Access97 users. The...
2
by: Robert McGregor | last post by:
Hi all, I've got a Front End / Back End database that was working just fine. One day i opened the FE to find that if I tried to open one of the linked tables from the database window, nothing...
4
by: Neil Ginsberg | last post by:
I have ODBC linked tables to a SQL 7 database in an A2K database. The linked tables do not have the password stored in them, so the first time the user accesses them, they need to enter the SQL...
7
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
3
by: Zlatko Matić | last post by:
Hi! What happens with linked tables if they were linked using File DSN, when I copy the Access file on some other PC without File DSN ? What is the difference between DSN on linked tables and...
2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
25
by: bubbles | last post by:
Using Access 2003 front-end, with SQL Server 2005 backend. I need to make the front-end application automatically refresh the linked SQL Server tables. New tables will be added dynamically in...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.