|
本帖最后由 鱼儿游游 于 2011-11-27 11:20 编辑
bpchan 发表于 2011-11-26 17:40
例子,难!
写一个函数给你,调用就行了。{:soso_e113:}
' 参数说明:
' IsCreateLinkTable .... 是否创建链接表: True_创建链接表、False_删除链接
' strSourceTableName ... 数据表的名称
' strLocalTableName .... 链接表的名称
'
Public Function LinkTable(IsCreateLinkTable As Boolean, strSourceTableName As String, strLocalTableName As String) As Boolean
On Error GoTo Err_Handler
Dim blnResult As Boolean
Dim dbs As Object
Dim tdf As Object
'删除原来的链接表
For Each tdf In dbs.TableDefs
If tdf.Name = strLocalTableName Then
dbs.TableDefs.Delete strLocalTableName
End If
Next
'重新创建链接表
If IsCreateLinkTable Then
Set tdf = dbs.CreateTableDef(strLocalTableName)
tdf.Connect =<变量名:数据库链接对象> '自己填上后台数据库链接对象的变量名就能用了。
tdf.SourceTableName = strSourceTableName
dbs.TableDefs.Append tdf
End If
blnResult = True
Exitr_Handler:
LinkTable = blnResult
Set dbs =Nothing
Set tdf =Nothing
Exit Function
Err_Handler:
blnResult = False
Resume Exitr_Handler
End Function
|
|