Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to reconnect to Linked tables in new directory 2

Status
Not open for further replies.

lhs24

Technical User
Aug 15, 2000
6
US
I found this code by Peter Vulovic for reconnecting to linked tables.

I am getting the following error when tring to run:

Complie error:
User-defined type not defined

It then points to the second line of code

Dim db As Database


Any ideas??

Function Reconnect()

Dim db As Database
Dim source As String
Dim path As String
Dim dbsource As String
Dim i As Integer
Dim j As Integer

Set db = DBEngine.Workspaces(0).Databases(0)

For i = Len(db.Name) To 1 Step -1

If Mid(db.Name, i, 1) = Chr(92) Then
path = Mid(db.Name, i, 1)
'MsgBox(path)

Exit For

End If

Next


For i = 0 To db.tabledefs.Count - 1

If db.tabledefs(i).connect <> &quot; &quot; Then
source = Mid(db.tabledefs(i).connect, 11)
'Debug.Print source
For j = Len(source) To 1 Step -1
If Mid(source, j, 1) = Chr(92) Then
dbsource = Mid(source, j + 1, Len(source))
source = Mid(source, 1, j)
If source <> path Then
db.tabledefs(i).connetc = &quot;;Database&quot; + path + dbsource
db.tabledefs(i).RefreshLink
'Debug.Print &quot;:Database=&quot; + path+ dbsource
End If
Exit For
End If
Next
End If

Next

End Function


 
If you're using Access 2000, it's because the 2000 uses the ADO library in lieu of the DAO library.
 
P.S.

Old:Dim dbs As DAO.Database
Set dbs = CurrentDb

New: Dim cnn As ADODB.Connection
Set cnn = CurrentProject.Connection

 

You can add the DAO library in Access 2000. Open a module in design mode. Click on Tools | References. Find the 'Microsoft DAO 3.x Object Library' (Choose the newest version available!) and check it. Click OK and the code should work. Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it if you have time.
 
Thanks Databaseguy and tlbroadbent I'm sure this will solve the problem!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top