creat table table_name field1 field1_type ;

解决方案 »

  1.   

    得用DAO。
    到MSDN里搜索createdatabase。
      

  2.   

    Dim StrMDBName As String             'New database'name (include full path)
       Dim db         As Database           'New database
       Dim tb         As Recordset          'New database's record
       Dim tbdef      As TableDef           'The define of the new database's table
       Dim dbField    As Field              'The field  of the new database
       Dim Idx        As Index              'The index  of the new database
       Dim Field_Type As Long               'The type   of the new database's field
       Dim lngFlag    As Long               ' field Flag
       
       Dim lngstart As Long                 'test time start
       Dim lngend   As Long                 'test time end
       
       On Error Resume Next
       
       lngstart = GetTickCount()
       
       StrMDBName = gStrFileWorkPath & "\" & gnewMdb_Attribute.strMdb_File_Name    'get the new mdb's name
       
       If Dir$(StrMDBName) <> "" Then
           Kill StrMDBName                  'If StrMDBName Existes then delete strMDBName
           Set db = Workspaces(0).CreateDatabase(StrMDBName, dbLangJapanese, dbVersion30)
       Else
           Set db = Workspaces(0).CreateDatabase(StrMDBName, dbLangJapanese, dbVersion30)
       End If
          
           Set tbdef = db.CreateTableDef(gnewMdb_Attribute.strMdb_Table_Name)  'Build table   '//Build field
       
        If bFlag Then
           Set dbField = tbdef.CreateField("_MFLAG", dbText, 1)
           dbField.AllowZeroLength = True
           tbdef.Fields.Append dbField
       End If
       
       For lngFlag = 1 To Val(gnewMdb_Attribute.strMdb_Field_Count)
           Select Case gnewField_Attribute(lngFlag).strMdb_Field_type
                  Case "Text":
                       Field_Type = dbText
                  Case "AutoNo"
                       Field_Type = dbText
                  Case "Date"
                       Field_Type = dbDate
                  Case "Long"
                       Field_Type = dbLong
                  Case "Byte"
                       Field_Type = dbByte
                  Case Else
                       Field_Type = -1
          End Select
          
          Set dbField = tbdef.CreateField(gnewField_Attribute(lngFlag).strMdb_Field_Name, Field_Type, _
                                        Val(gnewField_Attribute(lngFlag).strMdb_Field_Size))      If Field_Type = dbText Then
                dbField.AllowZeroLength = True    'If true then Allow Field Null else not allow null
          ElseIf Field_Type = dbLong Or _
                 Field_Type = dbByte Then
                dbField.DefaultValue = 0          'If Type is byte the default's value is  0
          End If
          dbField.Required = False                 'If true then the field's value must not be null
          tbdef.Fields.Append dbField
       Next lngFlag
       
       If bFlag Then
          For lngFlag = 1 To Val(gnewMdb_Attribute.strMdb_Field_Count)
             Set dbField = tbdef.CreateField("_" & gnewField_Attribute(lngFlag).strMdb_Field_Name, dbText, 1)
             dbField.AllowZeroLength = True
             tbdef.Fields.Append dbField
          Next lngFlag
       End If
       
       db.TableDefs.Append tbdef
       db.Close
       Set tbdef = Nothing
       Set db = Nothing