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

 

 

 

 

Executing Queries

A query statement returns a Recordset that you can use to view the data selected.

1a. Open the Recordset using its Open method.

Dim rs As ADODB.Recordset

 

Set rs = New ADODB.Recordset

rs.Open query, m_DBConnection, , , adCmdText

1b. Or use the Connection's Execute method.

Dim rs As ADODB.Recordset

 

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

2. Examine the records returned.

Do Until rs.EOF

    Debug.Print rs!Name    ' Display the name and address.

    Debug.Print rs!Street

    Debug.Print rs!City, rs!State, rs!Zip

 

    rs.MoveNext                 ' Get the next record.

Loop