473,394 Members | 1,794 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,394 software developers and data experts.

linking tables in runtime

121 100+
Hi,

I am trying to use the modRefreshTableLinks module in the samples database which links the tables to the north wind database. How do i get this to work with my own database ie which lines of code do i have to change for it to look up my tables?

Thanks Phill
Mar 11 '08 #1
1 2777
mshmyob
904 Expert 512MB
To link tables via code take a look at the following:

Expand|Select|Wrap|Line Numbers
  1. Function RefreshLinks() As Boolean
  2. Dim collTbls As Collection
  3. Dim i As Integer
  4. Dim strTbl As String
  5. Dim dbCurr As Database
  6. Dim dbLink As Database
  7. Dim tdfTables As TableDef
  8. Dim strBeFile As String
  9. Dim collTables As New Collection
  10. Dim tdf As TableDef
  11.  
  12. ' get the current linked table definitions
  13.     Set dbCurr = CurrentDb
  14.     dbCurr.TableDefs.Refresh
  15. ' end
  16.  
  17.     'First get all linked tables in a collection
  18.     For Each tdf In dbCurr.TableDefs
  19.         With tdf
  20.             If Len(.Connect) > 0 Then
  21.                     collTables.Add Item:=.Name & .Connect, Key:=.Name
  22.             End If
  23.         End With
  24.     Next
  25.     Set collTbls = collTables
  26.  
  27. ' change this string to your drive/directory/filename               
  28. strBeFile = "c:\any directory\backend file name.mdb"
  29.  
  30.             Set dbLink = DBEngine(0).OpenDatabase(strBeFile)
  31.  
  32.   ' start linking your tables - start from the last and work your way down
  33.      For i = collTbls.Count To 1 Step -1
  34.             strTbl = Left$(collTbls(i), InStr(1, collTbls(i), ";") - 1)
  35.                 Set tdfTables = dbCurr.TableDefs(strTbl)
  36.                 With tdfTables
  37.                     .Connect = ";Database=" & strBeFile
  38.                     .RefreshLink
  39.                 End With
  40.     Next
  41.    End Function
  42.  
This sample is hard coded for the directory of where your back end tables are. Before using this code you would first have to manually link the tables.

cheers,

Hi,

I am trying to use the modRefreshTableLinks module in the samples database which links the tables to the north wind database. How do i get this to work with my own database ie which lines of code do i have to change for it to look up my tables?

Thanks Phill
Mar 11 '08 #2

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

Similar topics

3
by: John South | last post by:
I have an Access 2000 front end that I wish to work with a SQL Server 2000 database by means of Linked tables. Do I have to use an ODBC connection to SQL Server? It seems to be the only option...
2
by: Jeff Pritchard | last post by:
Some time ago I am sure I came across something that said this was possible, though it doesn't seem to work. A client wants to replace an Access back-end with SQL Server tables. We have tried...
0
by: gasturbtec | last post by:
please help im new at access programming and i just got this project dropped in my lap because the old programmer quit. i've been doing ok so far but now i need to add code to an existing database...
18
by: Mark P | last post by:
I have a bit of vb code that uses Tables.Append to programatically link tables from Oracle and DB2 datasources. The problem I am having on some client machines is that the link will take anywhere...
5
by: Christoph Sticksel | last post by:
Hi, I'm having problems with attaching two tables stored in an SQL Server 2000 to an Access 97 database. It worked well for all other tables except those two. This is what I did: Choose the...
2
by: Matthew Wells | last post by:
Good morning... I have an Access front end that uses SQL Server linked tables. SQL Server uses Windows authentication. I have one Windows group that all Access users are a member of. I added...
7
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with...
1
by: deiopajw | last post by:
I have a Back end database on a network drive. The copies of the front end are located on individual pc's (in their C drive). The problem arises when a laptop user naturally hooks up to the...
10
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
3
by: ARC | last post by:
I'm having trouble here with Access 2007 and connecting to a different database. The code below works great IF the previous back-end database connection is still present and you are trying 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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.