如题。

解决方案 »

  1.   


    引用    Microsoft ADO Ext. 2.7 for DDL and SecurityThe following code shows how to create a new Microsoft Jet database with the Create method.Attribute VB_Name = "Create"
    Option Explicit' BeginCreateDatabseVB
    Sub CreateDatabase()   Dim cat As New ADOX.Catalog
       cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\new.mdb"End Sub
    ' EndCreateDatabaseVBThe following code demonstrates how to create a new table.' BeginCreateTableVB
    Sub CreateTable()   Dim tbl As New Table
       Dim cat As New ADOX.Catalog'Open the catalog.
       ' Open the Catalog.
       cat.ActiveConnection = _
          "Provider=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 tblEnd Sub
      

  2.   

    引用 Microsoft ADO Ext. 2.7 for DDL and Security
     
    The  following  code  shows  how  to  create  a  new  Microsoft  Jet  database  with  the  Create  method.  
     
    Attribute  VB_Name  =  "Create"  
    Option  Explicit  
     
    ' BeginCreateDatabseVB  
    Sub  CreateDatabase()  
     
         Dim  cat  As  New  ADOX.Catalog  
         cat.Create  "Provider=Microsoft.Jet.OLEDB.4.0;Data  Source=c:\new.mdb"  
     
    End  Sub  
    ' EndCreateDatabaseVB  
     
     
     
    The  following  code  demonstrates  how  to  create  a  new  table.  
     
    ' BeginCreateTableVB  
    Sub  CreateTable()  
     
         Dim  tbl  As  New  Table  
         Dim  cat  As  New  ADOX.Catalog  
     
    'Open  the  catalog.
         cat.ActiveConnection  =  _  
               "Provider=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  
     
    End  Sub  
     
      

  3.   

    'ADO不能建库,只能用ADOX
    Dim cat As ADOX.Catalog
    Dim tbl As ADOX.Table
    Dim con As ADODB.Connection    On Error GoTo 0    ' Create the new database.
        Set cat = New ADOX.Catalog
        cat.Create _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & DatabaseName & ";"    ' Create a new table.
        Set tbl = New ADOX.Table
        tbl.Name = "TestTable"
        tbl.Columns.Append "FirstName", adVarWChar, 40
        tbl.Columns.Append "LastName", adVarWChar, 40
        tbl.Columns.Append "Birthdate", adDate
        tbl.Columns.Append "Weight", adInteger
        cat.Tables.Append tbl 
       
    '设置列可以为NULL    
    tb1.columns("Weight").Attributes=AdColNullable

        ' Connect to the database.
        Set con = cat.ActiveConnection    ' Insert records.
        con.Execute "INSERT INTO TestTable VALUES ('Andy', 'Able', '1 Jan 1980', '150')"
        con.Execute "INSERT INTO TestTable VALUES ('Betty', 'Baker', #2/22/1990#, 70)"    ' Close the database connection.
        con.Close
        Set con = Nothing
        Set tbl = Nothing
        Set cat = Nothing
      

  4.   

    DAO方法
    Sub CreateDatabaseX()    Dim wrkDefault As Workspace
        Dim dbsNew As Database
        Set wrkDefault = DBEngine.Workspaces(0)
        Set dbsNew = wrkDefault.CreateDatabase("c:\NewDB.mdb", _
            dbLangGeneral, dbEncrypt)
        dbsNew.CloseEnd Sub