473,396 Members | 1,895 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.

Linked tables and ADO

Here is some code to refresh manage code in ADO/Access. Requires
"Microsoft ActiveX Data Objects 2.5 Library" as well as "Microsoft ADO
Ext. 2.5 for DDL and Security" references in the code.

I developed it as there seemed to be nothing out there that I could
google, only the DAO version that was getting somewhat dated.

Option Compare Database
Option Explicit
Const IntAttachedTableType As Integer = 6

Function fRefreshLinks(strPath As String) As Boolean

Dim strOldConnect As String, strNewConnect As String
Dim strFullLocation As String, strDatabase As String, strMsg As
String
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim MyDB As New ADOX.Catalog
Dim MyTable As ADOX.Table

MyDB.ActiveConnection = CurrentProject.Connection

Set cnn = CurrentProject.Connection
rst.Open "SELECT MSysObjects.Connect, MsysObjects.Database,
MSysObjects.Name from MSysObjects " & _
"WHERE MSysObjects.Type = " & IntAttachedTableType, cnn,
adOpenDynamic, adLockReadOnly

If rst.RecordCount <> 0 Then
rst.MoveFirst
On Error GoTo fRefreshLinks_Err
Set MyTable = MyDB.Tables(rst![Name].Value)
strOldConnect = MyTable.Properties(IntAttachedTableType).Value
strNewConnect = strPath
For Each MyTable In MyDB.Tables
If MyTable.Properties(IntAttachedTableType).Value =
strOldConnect Then
MyTable.Properties(IntAttachedTableType).Value =
strNewConnect
End If
Next MyTable
MyDB.Tables.Refresh
End If

fRefreshLinks_End:
rst.Close
cnn.Close
Set cnn = Nothing
Set rst = Nothing
Set MyDB = Nothing
Set MyTable = Nothing
fRefreshLinks = True
Exit Function

fRefreshLinks_Err:
fRefreshLinks = False
Select Case Err
Case 3024:

Case Else:
strMsg = "Error Information..." & vbCrLf & vbCrLf
strMsg = strMsg & "Function: fRefreshLinks" & vbCrLf
strMsg = strMsg & "Description: " & Err.Description &
vbCrLf
strMsg = strMsg & "Error #: " & Format$(Err.Number) &
vbCrLf
MsgBox strMsg, vbOKOnly + vbCritical, "Error"
End Select
Exit Function
End Function

Public Function FileName(strFullLocation As String)

Dim intlen As Integer, i As Integer

'Get the Database Name, for use on the 'Find File' Form Caption
intlen = Len(strFullLocation)
For i = intlen To 1 Step -1
If Mid$(strFullLocation, i, 1) = "\" Then
FileName = Right$(strFullLocation, intlen - i)
Exit For
End If
Next i

End Function
Nov 12 '05 #1
0 3181

This thread has been closed and replies have been disabled. Please start a new discussion.

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: 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...
5
by: b b | last post by:
I created the following code to delete all linked tables in my database (Access 200): -------------------------------------------------------- Dim tbl As TableDef Dim dbs As Database Set dbs...
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,...
10
by: Jim Devenish | last post by:
I have a split front end/back end system. However I create a number of local tables to carry out certain operations. There is a tendency for the front end to bloat so I have set 'compact on...
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: 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...
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
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...

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.