PLMM问我ACCESS怎么用SQL语句改字段类型为自动编号?

解决方案 »

  1.   

    终于找到一些相关的,SQL楼主再找找吧 
    Sub CreateAutoNumberField(strDBPath As String)
       Dim catDB As ADOX.Catalog
       Dim tbl As ADOX.Table   Set catDB = New ADOX.Catalog
       ' Open the catalog.
       catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" _
          & "Data Source=" & strDBPath   Set tbl = New ADOX.Table
       With tbl
          .Name = "Contacts"
          Set .ParentCatalog = catDB
          ' Create fields and append them to the
          ' Columns collection of the new Table object.
          With .Columns
             .Append "ContactId", adInteger
             ' Make the ContactId field auto-incrementing.
             .Item("ContactId").Properties("AutoIncrement") = True
             .Append "CustomerID", adVarWChar
             .Append "FirstName", adVarWChar
             .Append "LastName", adVarWChar
             .Append "Phone", adVarWChar, 20
             .Append "Notes", adLongVarWChar
          End With
       End With   ' Add the new Table to the Tables collection of the database.
       catDB.Tables.Append tbl   Set catDB = Nothing
    End Sub