设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[与其它组件] 怎样用VB新建外部MDB文件.

[复制链接]
1#
发表于 2008-3-25 18:31:00 | 显示全部楼层
Dim CatalogX As New ADOX.Catalog
Dim ConnX As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub cmdOK_Click()
    If txtDBName.Text = "" Then
        MsgBox "请输入要生成的数据库名.", vbInformation
        txtDBName.SetFocus
        Exit Sub
    End If
   
    If Dir(txtDBName.Text) <> "" Then
        MsgBox "要生成的数据库名已存在.", vbInformation
        txtDBName.SetFocus
        Exit Sub
    End If
   
    Dim ConnString As String
   
    ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;"
    ConnString = ConnString & "Data Source=" & txtDBName.Text
On Error GoTo CreateErr
    '创建数据库
    CatalogX.Create ConnString
    CatalogX.ActiveConnection = ConnString
    '建立新表格
    Dim TableX As New Table
    TableX.Name = "MyTable"
    '向表格中添加字段并指定字段类型
    TableX.Columns.Append "ID", adInteger
    TableX.Columns.Append "Name", adVarWChar, 8
    TableX.Columns.Append "Address", adVarWChar, 50
    '向数据库中添加表格
    CatalogX.Tables.Append TableX
    Exit Sub
CreateErr:
    MsgBox "创建数据库时发生错误:" & Err.Description, vbInformation
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-14 09:41 , Processed in 0.172207 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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