适用于:Access 2013、Office 2013
设置或返回一个值,该值指示零长度字符串 (“”) 是否是 Field2 对象的 Value 属性的有效设置,该对象具有文本或备注数据类型, (Microsoft Access 工作区仅) 。
语法
表达式 。AllowZeroLength
表达式 一个表示 Field2 对象的变量。
备注
对于尚未追加到 Fields 集合中的对象,该属性是可读写的。
将对象追加到 Fields 集合后, AllowZeroLength 属性的可用性将取决于包含 Fields 集合的对象,如下表所示。
如果 Fields 集合属于 |
则 AllowZeroLength |
|---|---|
Index 对象 |
不受支持 |
QueryDef 对象 |
只读 |
Recordset 对象 |
只读 |
Relation 对象 |
不支持 |
TableDef 对象 |
读/写 |
可将该属性与 Required 、 ValidateOnSet 或 ValidationRule 属性一起使用,以验证字段中的值。
示例
在以下示例中, AllowZeroLength 属性允许用户将 Field2 的值设置为空字符串。 在这种情况下,用户可区分数据未知的记录和未应用数据的记录。
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.Close
End Sub