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

 

 

 

 

One Column Queries

These queries are particularly useful for getting a list of values form a dictionary table. You can use the results to initialize ComboBoxes, ListBoxes, etc.

Public Function ExecuteOneColumnQuery( _

    ByVal query As String) As Collection

Dim results As Collection

Dim rs As ADODB.Recordset

 

    Set results = New Collection

 

    ' Execute the query.

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

 

    ' Save the results in the collection.

    Do Until rs.EOF

        results.Add rs.Fields(0).Value

        rs.MoveNext

    Loop

 

    ' Close the Recordset.

    rs.Close

 

    ' Return the collection.

    Set ExecuteOneColumnQuery = results

End Function