设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 885|回复: 2
打印 上一主题 下一主题

[其它] 请问如何在表中自动建立新的字段

[复制链接]
跳转到指定楼层
1#
发表于 2006-4-23 01:49:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式


请问如何让表自动建立新的字段
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2006-4-23 02:57:00 | 只看该作者
在表中不能完成.下例用的ADOX实现的,也可以采用SQL

Columns 和 Tables 的 Append 方法、Name 属性范例 (VB)

下面的代码演示如何创建新的表。' BeginCreateTableVB
Sub Main()
    On Error GoTo CreateTableError
   
    Dim tbl As New Table
    Dim cat As New ADOX.Catalog
   
    ' Open the Catalog.
    cat.ActiveConnection = "rovider='Microsoft.Jet.OLEDB.4.0';" & _
        "Data Source='c:\Program Files\Microsoft Office\" & _
        "Office\Samples\Northwind.mdb';"
   
    tbl.Name = "MyTable"
    tbl.Columns.Append "Column1", adInteger
    tbl.Columns.Append "Column2", adInteger
    tbl.Columns.Append "Column3", adVarWChar, 50
    cat.Tables.Append tbl
    Debug.Print "Table 'MyTable' is added."
   
    'Delete the table as this is a demonstration.
    cat.Tables.Delete tbl.Name
    Debug.Print "Table 'MyTable' is deleted."
   
    'Clean up
    Set cat.ActiveConnection = Nothing
    Set cat = Nothing
    Set tbl = Nothing
    Exit Sub
   
CreateTableError:

    Set cat = Nothing
    Set tbl = Nothing

    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub
' EndCreateTableVB

[此贴子已经被作者于2006-4-22 18:58:02编辑过]

3#
 楼主| 发表于 2006-4-23 03:05:00 | 只看该作者
谢谢 fan0217 版大

我研究研究~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-25 09:51 , Processed in 0.274707 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表