0

有人请帮助我在运行时使用 VB 6.0 在特定位置(例如 E:\MMDataBase)创建 MS Access 数据库 .accdb 扩展文件,并帮助我在同一数据库中创建表。

MS Access 2007 已安装在我的计算机中

谢谢

4

1 回答 1

1

The ACE database engine is essentially an extended version of Jet 4.0 and contains much of Jet 4.0 with support for the new format on top of that. As a result both the SQL DML and DDL syntax is quite similar to Jet 4.0 SQL.

I'm not sure whether installing Access 2007 installs the ACE Provider or not. Perhaps it is an optional item in the Access 2007 installer? In any case a separate Microsoft download exists that can be used to install the necessary software even when you don't have Access 2007 at all.

See 2007 Office System Driver: Data Connectivity Components

Once that's in place the process is basically identical to doing this with Jet. Example:

Private Sub CreateDB()
    'Reference required:
    '
    '   Microsoft ActiveX Data Objects 2.5 Library (or later).
    '
    'OLEDB Provider required:
    '
    '   Access Database Engine 2007.

    Dim catDB As Object
    Dim cnDB As ADODB.Connection

    Set catDB = CreateObject("ADOX.Catalog")
    With catDB
        .Create "Provider=Microsoft.ACE.OLEDB.12.0;" _
              & "Data Source='D:\sample.accdb'"
        Set cnDB = .ActiveConnection
    End With
    Set catDB = Nothing
    With cnDB
        .Execute "CREATE TABLE ClassDates(" _
               & "Id IDENTITY CONSTRAINT PK_UID PRIMARY KEY," _
               & "Student TEXT(12) WITH COMPRESSION NOT NULL," _
               & "ClassDate DATETIME NOT NULL," _
               & "PaidFor YESNO DEFAULT False," _
               & "CONSTRAINT StudentDates UNIQUE (" _
               & "Student, ClassDate))", , _
                 adCmdText Or adExecuteNoRecords
        .Close
    End With
End Sub
于 2013-07-08T12:14:20.420 回答