G
Guest
I can access every table and i can add a column using ADOX. How do I get the
2 to work together?
Function testFindTables() As Boolean
Dim tblSub CreateAutoNumberField(strDBPath As String)
Dim catDB As ADOX.Catalog
Dim tbl As ADOX.Table
Dim okey As ADOX.Key
Set okey = New ADOX.Key
Set catDB = New ADOX.Catalog
' Open the catalog.
catDB.ActiveConnection = CurrentProject.Connection
'"Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "Data Source=" & strDBPath
Set tbl = New ADOX.Table
With tbl
.Name = "Contacts"
Set .ParentCatalog = catDB ' Create fields and append
them to the
' Columns collection of the
new Table object.
With .Columns
.Append "ContactId", adInteger ' Make the ContactId field
auto-incrementing.
.Item("ContactId").Properties("AutoIncrement") = True
End With
catDB.Tables.Append tbl
With okey
.Name = "PrimaryKey"
.Type = adKeyPrimary
.RelatedTable = "contacts"
.Columns.Append "contactID"
End With
catDB.Tables("contacts").Keys.Append okey
End With
' Add the new Table to the Tables collection of the database.
'catDB.Tables.Append tbl
Set catDB = Nothing
End Sub1 As ADODB.TableDef
Dim result As VbMsgBoxResult
For Each tbl In CurrentDb.TableDefs
result = MsgBox("Do you want to delete " & tbl.Name, vbYesNo,
"Delete table...")
If result = vbYes Then
result = MsgBox("Are you sure you want to PERMANENTLY delete " &
tbl.Name & "'from the database???", vbYesNo, "Confirm delete...")
If result = vbYes Then
DoCmd.CopyObject , tbl.Name + 1, acTable, tbl1.Name
End If
End If
Next tbl
testFindTables = True 'Function completes OK
End Function
2 to work together?
Function testFindTables() As Boolean
Dim tblSub CreateAutoNumberField(strDBPath As String)
Dim catDB As ADOX.Catalog
Dim tbl As ADOX.Table
Dim okey As ADOX.Key
Set okey = New ADOX.Key
Set catDB = New ADOX.Catalog
' Open the catalog.
catDB.ActiveConnection = CurrentProject.Connection
'"Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "Data Source=" & strDBPath
Set tbl = New ADOX.Table
With tbl
.Name = "Contacts"
Set .ParentCatalog = catDB ' Create fields and append
them to the
' Columns collection of the
new Table object.
With .Columns
.Append "ContactId", adInteger ' Make the ContactId field
auto-incrementing.
.Item("ContactId").Properties("AutoIncrement") = True
End With
catDB.Tables.Append tbl
With okey
.Name = "PrimaryKey"
.Type = adKeyPrimary
.RelatedTable = "contacts"
.Columns.Append "contactID"
End With
catDB.Tables("contacts").Keys.Append okey
End With
' Add the new Table to the Tables collection of the database.
'catDB.Tables.Append tbl
Set catDB = Nothing
End Sub1 As ADODB.TableDef
Dim result As VbMsgBoxResult
For Each tbl In CurrentDb.TableDefs
result = MsgBox("Do you want to delete " & tbl.Name, vbYesNo,
"Delete table...")
If result = vbYes Then
result = MsgBox("Are you sure you want to PERMANENTLY delete " &
tbl.Name & "'from the database???", vbYesNo, "Confirm delete...")
If result = vbYes Then
DoCmd.CopyObject , tbl.Name + 1, acTable, tbl1.Name
End If
End If
Next tbl
testFindTables = True 'Function completes OK
End Function