For Each tdf in backup_db.TableDefs
If (tdf.attributes And dbSystemObject)=0 Then
//条件成立,说明该表是用户定义的表,可以链接,否则跳过
End if
Next
③ 使用Create_Table()对每个表创建与之对应的备份表,取名可遵循如下原则, 若原表叫table_name, 则备份表叫b_table_name。
④ 将table_name表中的所有记录复制到b_table_name中。
⑤从备份库删除对SQL数据表的链接。
3、程序原码
采用微软DAO (Data Access Object) 数据模型, 打开Access 本地数据库, 并连接一个外部ODBC数据表, 拷贝该表结构完成, 有以下过程块CopyStru :
Private Sub copyStru ()
Set dbsTemp = wrkjet. OpenDatabase (tagFilName)// 链接表的过程
For i = 0 To tabN - 1
Set tdfLinked = dbsTemp. CreateTableDef (“linkTab”)
tdfLinked. Connect = “OdbC; DATABASE = xgsbgsys ; UID =
sa ; PWD = ; DSN = xgsdb ;”
tdfLinked. SourceTableName = tabName (i)
dbsTemp. TableDefs. Append tdfLinked
Set temp Tab = dbsTemp. CreateTableDef ()
temp Tab. Name = tabName (i)
//创建新表的过程
For Each fld In tdfLinked. Fields
Set newFil = temp Tab. CreateField (fld. Name , fld. Type ,fld. Size)
newFil. OrdinalPosition = fld. OrdinalPosition
newFil. Required = fld. Required
temp Tab. Fields. Append newFil
Next
//创建索引
For Each idx In tdfLinked. Indexes
Set newIdx = temp Tab. CreateIndex ()
With newIdx
Name = tabName (i) & ” x”
Fields = idx. Fields
Unique = idx. Unique
Primary = idx. Primary
End With
temp Tab. Indexes. Append newIdx
Next
dbsTemp. TableDefs. Append temp Tab
Set temp Tab = Nothing
dbsTemp. TableDefs. Delete ”linkTab”
Next i
dbsTemp. Close
Set dbsTemp = Nothing
wrkjet. Close
Set wrkjet = Nothing
End Sub
End Sub
[1]