创建的是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" --->"是否允许空值 处,仍为 ‘否’",
有什么办法 能让其变为 “是” 呢?
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" --->"是否允许空值 处,仍为 ‘否’",
有什么办法 能让其变为 “是” 呢?
===============' 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
一般文件所在目录 \Common Files\System\ADO\msadox.dll
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
谢谢。