ADO Tips & Tricks1) Connection Objecta)
Opening the Database
b)
Executing Commands
c)
Executing Queries
d)
Closing the Database
2) Recordset Objecta)
The Fields Collection
b)
Editing Records
3) Toolsa)
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 Examplea)
The SELECT Clause
b)
The WHERE Clause
c)
The Query
|
The
WHERE Clause
' Build a WHERE clause from the
user's selections.
Private Function WhereClause() As String
Dim where_clause As String
Dim i As Integer
For
i = cboField.LBound To cboField.UBound
' See if this row has a non-blank field and operator.
If Len(cboField(i).Text) > 0 And _
Len(cboOperator(i).Text) > 0 _
Then
' Add this row to the whare clause.
If cboOperator(i).Text =
"IS NULL" Or _
cboOperator(i).Text = "IS NOT NULL" _
Then
' IS NULL or IS NOT NULL.
where_clause = where_clause & _
"(" & cboField(i).Text &
" " & _
cboOperator(i).Text & _
") AND "
Else
' Field Operator Value.
where_clause = where_clause & _
"(" & cboField(i).Text &
" " & _
cboOperator(i).Text & " '"
& _
SQLSafe(txtValue(i).Text) & _
"') AND "
End If
End If
Next i
' Remove the trailing " AND " if necessary.
If Len(where_clause) > 0 Then
where_clause = "WHERE " & _
Left$(where_clause, Len(where_clause) - 5)
End If
WhereClause = where_clause
End Function
|