创建的是access 2000库 或 97 库
  tempado.CommandText = "Create table " & crtTblname & " (myfield1 int null,myfield2 int NULL ," & _
    "Myfield3 char(20) NULL," & _
    "Myfield4 char(4) NULL , " & _
    "Myfield5 char(10) NULL ," & _
    "Myfield6 char(10) NULL "
... ...
创建后的表结构 ,查看 “设计视图” ---> "myfield5" --->"是否允许空值 处,仍为 ‘否’",
 有什么办法 能让其变为 “是” 呢?
  

解决方案 »

  1.   

    引用:    Microsoft ADO Ext. 2.7 for DDL and Security
    ===============' BeginAttributesVB
    Sub AttributesX()    Dim cnn As New ADODB.Connection
        Dim cat As New ADOX.Catalog
        Dim colTemp As New ADOX.Column
        Dim rstEmployees As New Recordset
        Dim strMessage As String
        Dim strInput As String
        Dim tblEmp As ADOX.Table
        
        ' Connect the catalog.
        cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=c:\" & _
            "Program Files\Microsoft Office\Office\Samples\Northwind.mdb;"
        Set cat.ActiveConnection = cnn    Set tblEmp = cat.Tables("Employees")
        
        ' Create a new Field object and append it to the Fields
        ' collection of the Employees table.
        colTemp.Name = "FaxPhone"
        colTemp.Type = adVarWChar
        colTemp.DefinedSize = 24'下面设置允许空值
        colTemp.Attributes = adColNullable
    '
        cat.Tables("Employees").Columns.Append colTemp
        
        ' Open the Employees table for updating as a Recordset
        rstEmployees.Open "Employees", cnn, adOpenKeyset, adLockOptimistic
        
        With rstEmployees
            ' Get user input.
            strMessage = "Enter fax number for " & _
                !FirstName & " " & !LastName & "." & vbCr & _
                "[? - unknown, X - has no fax]"
            strInput = UCase(InputBox(strMessage))
            If strInput <> "" Then
                Select Case strInput
                    Case "?"
                        !FaxPhone = Null
                    Case "X"
                        !FaxPhone = ""
                    Case Else
                        !FaxPhone = strInput
                End Select
                .Update
                
                ' Print report.
                Debug.Print "Name - Fax number"
                Debug.Print !FirstName & " " & !LastName & " - ";            If IsNull(!FaxPhone) Then
                    Debug.Print "[Unknown]"
                Else
                    If !FaxPhone = "" Then
                        Debug.Print "[Has no fax]"
                    Else
                        Debug.Print !FaxPhone
                    End If
                End If        End If        .Close
        End With    ' Delete new field because this is a demonstration.
        tblEmp.Columns.Delete colTemp.Name
        cnn.Close
        
    End Sub
    ' EndAttributesVB
      

  2.   

    就是说,用 colTemp.Attributes = adColNullable 这一句了,还得去microsoft 下 ado2.7 吧?
      

  3.   

    你的vb6里面没有ADOX库嘛?
    一般文件所在目录 \Common Files\System\ADO\msadox.dll
      

  4.   

    它告我不能加载 Common Files\System\ADO\msadox.dll
      

  5.   

    create table语句只能设置NOT NULL(不是NULL),意思是成为必填字段,和是否允许空字串没有关系。
      

  6.   

    AllowZeroLength Property 例子此例中,AllowZeroLength属性是用户可以设置字段为空字符串。Sub AllowZeroLengthX()   Dim dbsNorthwind As Database
       Dim tdfEmployees As TableDef
       Dim fldTemp As Field
       Dim rstEmployees As Recordset
       Dim strMessage As String
       Dim strInput As String   Set dbsNorthwind = OpenDatabase("Northwind.mdb")
       Set tdfEmployees = dbsNorthwind.TableDefs("Employees")
       ' Create a new Field object and append it to the Fields 
       ' collection of the Employees table.
       Set fldTemp = tdfEmployees.CreateField("FaxPhone", _
          dbText, 24)
       fldTemp.AllowZeroLength = True
       tdfEmployees.Fields.Append fldTemp   Set rstEmployees = _
          dbsNorthwind.OpenRecordset("Employees")   With rstEmployees
          ' Get user input.
          .Edit
          strMessage = "Enter fax number for " & _
             !FirstName & " " & !LastName & "." & vbCr & _
             "[? - unknown, X - has no fax]"
          strInput = UCase(InputBox(strMessage))
          If strInput <> "" Then
             Select Case strInput
                Case "?"
                   !FaxPhone = Null
                Case "X"
                   !FaxPhone = ""
                Case Else
                   !FaxPhone = strInput
             End Select         .Update         ' Print report.
             Debug.Print "Name - Fax number"
             Debug.Print !FirstName & " " & !LastName & " - ";         If IsNull(!FaxPhone) Then
                Debug.Print "[Unknown]"
             Else
                If !FaxPhone = "" Then
                   Debug.Print "[Has no fax]"
                Else
                   Debug.Print !FaxPhone
                End If
             End If      Else
             .CancelUpdate
          End If      .Close
       End With   ' Delete new field because this is a demonstration.
       tdfEmployees.Fields.Delete fldTemp.Name
       dbsNorthwind.CloseEnd Sub
      

  7.   

    你们两个一样啊,可我没法引用ado2.7 ext
      

  8.   

    dao 是 不太可能用了,那样我的改动很大,我再试一试其他办法。
    谢谢。