Home

Column Value Listing

 

Introduction

When checking the values of a table, query, form, or report, you may want to visit the values of a particular column and only that column. The records of such an object are kept in the Recordset object. You can use it to visit each column and find out the value stored under it.

Imagine you create a table named People like this:

Imagine you want to get the values stored in the Full Name column. You can use code as follows:

Option Compare Database
Option Explicit

Private Sub cmdFullNames_Click()
    Dim rstPeople As ADODB.Recordset
    Dim fldFullName As Field
    Dim strFullName As String
    
    Set rstPeople = New ADODB.Recordset
    
    rstPeople.Open "People", CurrentProject.Connection, _
			adOpenStatic, adLockOptimistic
    
    strFullName = " =-= Full Names =-=" & vbCrLf
    
    With rstPeople
        While Not .EOF
            For Each fldFullName In .Fields
                If fldFullName.Name = "FullName" Then
                    strFullName = strFullName & fldFullName.Value & vbCrLf
                End If
            Next
            .MoveNext
        Wend
    End With
    
    MsgBox strFullName
    
    rstPeople.Close
    Set rstPeople = Nothing
End Sub

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click


    DoCmd.Close

Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click
    
End Sub
 
 

Home Copyright © 2005-2016, FunctionX