PSS ID Number: 108423
Article Last Modified on 11/7/2003
Dim Db As Database
Set Db = OpenDatabase("BIBLIO.MDB")
Sub Form_Load ()
Dim db As database
Dim td As New Tabledef
Dim ds As dynaset
Set db = OpenDatabase("BIBLIO.MDB")
td.Name = "MyNewCustomersTable" ' New Table name for use in VB.
td.SourceTableName = "Customers" ' Table name in source database.
td.Connect = ";DATABASE=c:\access\nwind.mdb;" ' Source database.
db.TableDefs.Append td ' Append Customers Table to BIBLIO.MDB.
Set ds = db.CreateDynaset("MyNewCustomersTable") ' Create dynaset.
Debug.Print ds.Fields(0) ' Proves the Table is attached.
Debug.Print ds.Fields(1) ' Proves the Table is attached.
Debug.Print ds.Fields(2) ' Proves the Table is attached.
' The following statement deletes the appended Table, if desired:
db.TableDefs.Delete "MyNewCustomersTable"
End Sub
Sub Form_Load ()
Dim db1 As database, db2 As database
Dim td As New Tabledef
Dim tb As Table
Dim ds As dynaset
Dim f1 As New field, f2 As New field
Const DB_LANG_GENERAL = ";LANGID=0x0809;CP=1252;COUNTRY=0"
Const DB_VERSION10 = 1
Const file1 = "test1.mdb" 'contains Table food1"
Const file2 = "test2.mdb" 'contains Table food2
Set db1 = OpenDatabase(file1)
Set db2 = OpenDatabase(file2)
' db2.TableDefs.Delete "new_food1" ' Deletes Table if desired.
td.Name = "new_food1"
td.SourceTableName = "food1"
td.Connect = ";database=" & file1 & ";"
' NOTE: For an ODBC database, the connect string would be similar to:
' td.Connect = "ODBC;Username=<username>;PWD=<strong password>;DSN=texas;DATABASE=pubs;"
' td.Attributes = DB_ATTACHEDTABLE
' or, if password protected: td.Attributes = &H20000
' or, if exclusive: td.Attributes = tbl.Attributes + &H10000
db2.TableDefs.Append td ' Attaches the external Table.
' NOTE: The OpenTable method is illegal for attached Tables:
' Set tb = db2.OpenTable("new_food1") ' Gives an error.
Set ds = db2.CreateDynaset("new_food1")
Print ds.Fields(0) ' Proves the Table is attached.
ds.Close
db1.Close
db2.Close
End Sub
Additional query words: 3.00
Keywords: KB108423
Technology: kbAudDeveloper kbVB300 kbVB300Search kbVBSearch kbZNotKeyword2 kbZNotKeyword6