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!

Link all tables

Status
Not open for further replies.

mypeljo

Technical User
Apr 16, 2010
12
BG
I have a working code linking all table.I want to rearrange it so that the table "calls" is not linked.Can you help me? My code is the following:
Public Function LinkAllTables(DBName)
'link all user tables in source database
Dim FrontDB As DAO.Database, BackDB As DAO.Database
Dim Tbl As DAO.TableDef, Lnk As DAO.TableDef

Set FrontDB = CurrentDb
Set BackDB = OpenDatabase(DBName)

For Each Tbl In BackDB.TableDefs
If Tbl.Attributes = 0 Then
Set Lnk = FrontDB.CreateTableDef( _
Name:=Tbl.Name)
Lnk.SourceTableName = Tbl.Name
Lnk.Connect = ";DATABASE=" & BackDB.Name
FrontDB.TableDefs.Append Lnk
End If
Next
DoCmd.Beep
End Function
 
Try:
Code:
Public Function LinkAllTables(DBName)
'link all user tables in source database
   Dim FrontDB As DAO.Database, BackDB As DAO.Database
    Dim Tbl As DAO.TableDef, Lnk As DAO.TableDef
    
    Set FrontDB = CurrentDb
    Set BackDB = OpenDatabase(DBName)
    
    For Each Tbl In BackDB.TableDefs
        If Tbl.Attributes = 0 AND Tbl.Name <> "calls" Then
            Set Lnk = FrontDB.CreateTableDef( _
                Name:=Tbl.Name)
            Lnk.SourceTableName = Tbl.Name
            Lnk.Connect = ";DATABASE=" & BackDB.Name
            FrontDB.TableDefs.Append Lnk
        End If
    Next
    DoCmd.Beep
End Function
I would probably create another optional parameter to pass to the function that would contain the names of the tables to not link.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top