ADO Tips & Tricks

1)     Connection Object

a)      Opening the Database

b)      Executing Commands

c)       Executing Queries

d)      Closing the Database

2)     Recordset Object

a)      The Fields Collection

b)      Editing Records

3)     Tools

a)      One Column Queries

b)      ComboBox Example

c)       One Row Queries

d)      Multi-Column Queries

e)      Getting Field Names

f)        ComboBox Example, 2

4)     A Useful Example

a)      The SELECT Clause

b)      The WHERE Clause

c)       The Query

 

Download Example Programs

 

 

 

 

Getting Field Names

You can use the Recordset object and its Fields collection to get the names of the columns returned by a query.

Public Function GetQueryFields(ByVal query As String) _

    As Collection

Dim results As Collection

Dim rs As ADODB.Recordset

Dim field_num As Integer

 

    Set results = New Collection

 

    ' Execute the query.

    Set rs = m_DBConnection.Execute(query, , adCmdText)

 

    ' Save the field names in the collection.

    For field_num = 0 To rs.Fields.Count - 1

        results.Add rs.Fields(field_num).Name

    Next field_num

 

    ' Close the Recordset.

    rs.Close

 

    ' Return the collection.

    Set GetQueryFields = results

End Function