Field2.AllowZeroLength プロパティ (DAO)

適用先: Access 2013、Office 2013

長さ 0 の文字列 ("") が、Text または Memo データ型 (Microsoft Access ワークスペースのみ) を持つ Field2 オブジェクトの Value プロパティの有効な設定であるかどうかを示す値を設定または返します。

構文

式 。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