Search code examples
loopsms-accessvba

How to Loop through a specific column in a table


New to Access VBA and need some assistance. I have a table with a boolean field I am trying to loop through to locate all of the "False" fields. Once located I want to display a messagebox containing the ID number and some basic information. My table is housed in a SQL database. Thanks for the help!


Solution

  • You could use GetString. Here's an example

    Public Sub MsgBoxActives()
    
        Dim rs As ADODB.Recordset
        Dim cn As ADODB.Connection
    
        Set cn = CurrentProject.Connection
        Set rs = cn.Execute("SELECT CUSTOMERID, DISCOUNT FROM [Volume Rebate Customers] WHERE not [INACTIVE?];")
    
        MsgBox rs.GetString
    
    End Sub