--- title: "IndexNulls Property Example (VB) | Microsoft Docs" ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.custom: "" ms.date: "01/19/2017" ms.reviewer: "" ms.topic: conceptual dev_langs: - "VB" helpviewer_keywords: - "IndexNulls property [ADOX], Visual Basic example" ms.assetid: 45204669-32c0-4690-aab9-ddf0fd71ae48 author: MightyPen ms.author: genemi --- # IndexNulls Property Example (VB) This example demonstrates the [IndexNulls](../../../ado/reference/adox-api/indexnulls-property-adox.md) property of an [Index](../../../ado/reference/adox-api/index-object-adox.md). The code creates a new index and sets the value of **IndexNulls** based on user input (from a list box named List1). Then, the **Index** is appended to the **Employees** [Table](../../../ado/reference/adox-api/table-object-adox.md) in the *Northwind* [Catalog](../../../ado/reference/adox-api/catalog-object-adox.md). The new **Index** is applied to a [Recordset](../../../ado/reference/ado-api/recordset-object-ado.md) based on the **Employees** table, and the **Recordset** is opened. A new record is added to the **Employees** table, with a **Null** value in the indexed field. Whether this new record is displayed depends on the setting of the **IndexNulls** property. ``` ' BeginIndexNullsVB Private Sub cmdIndexNulls_Click() IndexNullsX End Sub Sub IndexNullsX() Dim cnn As New ADODB.Connection Dim catNorthwind As New ADOX.Catalog Dim idxNew As New ADOX.Index Dim rstEmployees As New ADODB.Recordset Dim varBookmark As Variant ' Connect the catalog. cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "data source=c:\Program Files\" & _ "Microsoft Office\Office\Samples\Northwind.mdb;" Set catNorthwind.ActiveConnection = cnn ' Append Country column to new index idxNew.Columns.Append "Country" idxNew.Name = "NewIndex" ' Set IndexNulls based on user selection in listbox List1 Select Case List1.List(List1.ListIndex) Case "Allow" idxNew.IndexNulls = adIndexNullsAllow Case "Ignore" idxNew.IndexNulls = adIndexNullsIgnore Case Else End End Select 'Append new index to Employees table catNorthwind.Tables("Employees").Indexes.Append idxNew rstEmployees.Index = idxNew.Name rstEmployees.Open "Employees", cnn, adOpenKeyset, _ adLockOptimistic, adCmdTableDirect With rstEmployees ' Add a new record to the Employees table. .AddNew !FirstName = "Gary" !LastName = "Haarsager" .Update ' Bookmark the newly added record varBookmark = .Bookmark ' Use the new index to set the order of the records. .MoveFirst Debug.Print "Index = " & .Index & _ ", IndexNulls = " & idxNew.IndexNulls Debug.Print " Country - Name" ' Enumerate the Recordset. The value of the ' IndexNulls property will determine if the newly ' added record appears in the output. Do While Not .EOF Debug.Print " " & _ IIf(IsNull(!Country), "[Null]", !Country) & _ " - " & !FirstName & " " & !LastName .MoveNext Loop ' Delete new record because this is a demonstration. .Bookmark = varBookmark .Delete .Close End With ' Delete new Index because this is a demonstration. catNorthwind.Tables("Employees").Indexes.Delete idxNew.Name Set catNorthwind = Nothing End Sub ' EndIndexNullsVB ``` ## See Also [Index Object (ADOX)](../../../ado/reference/adox-api/index-object-adox.md) [IndexNulls Property (ADOX)](../../../ado/reference/adox-api/indexnulls-property-adox.md)