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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting and creating table links in VBA

Status
Not open for further replies.

JeffCharvat

Programmer
Feb 19, 2002
3
0
0
US
I have a backend db (tables only), a middle db (with everything except the tables but with links to the tables) and an MDE file. I develop locally and integrate to the network when necessary.

What I want to be able to do is easily switch which backend db my table links point to. I wrote a routine that updates all the middle db's tabledefs connect string and refreshes appropriately. Problem is that the routine does not compensate for added or deleted tables in the backend file.

So I was thinking I would delete all the linked tables and create new ones. But I can't figure out how to do it. I'm assuming its doable and I'm just not looking in the right place.

Anyone know how to delete and create linked tables in a db?

Thanks,
Jeff
 
I have a "utilities" form that I don't expose to users, that has labels where the click events will show the current BE table paths and delete the paths.

It's much easier to delete table links in code. I've actually had some weird transaction errors occur at the hidden level due to network timing issues and asking for rapid manual deletions of table links--this never happens with code.

Here's the delete links code:
[tt]
Public Sub DeleteLinks()
On Error Resume Next
Dim Db As DAO.Database
Dim Tdfs As DAO.TableDefs
Dim strTable As String
Dim intCount As Integer

Set Db = CurrentDb

Set Tdfs = Db.TableDefs

For intCount = (Tdfs.Count - 1) To 0 Step -1

If Left(Tdfs(intCount).Name, 4) <> &quot;Msys&quot; Then

If Len(Tdfs(intCount).Connect) Then

Tdfs.Delete (Tdfs(intCount).Name)

End If

End If

Next

MsgBox &quot;Done&quot;

End Sub

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top