|
The SQL Like Predicate
in a DBCombo Control
by Rick Meyer
|
|
|
The LIKE predicate in an SQL statement gives you the opportunity to use wildcard characters to match records in a database. The following brief demo uses the * character to return records that match anything following the text that is typed into a DBCombo Control.
The wildcard could be used at the start of the match string as well. Other wildcard chararacters include ? for any char and # for a numerical digit.
|
|
Instructions for Building this Project:
1. Start a new professional exe.
2. On Form1 put a Data Control named Data1
3. In Data1.DatabaseName choose nwind.mdb
4. On Form1 put a DBCombo Control named DBCombo1
5. Set the DBCombo1.Style property to 1-dbcSimple
6. Set the DBCombo1.RowSource property to Data1
7. Type in the DBCombo1.Listfield: CompanyName
      Form1 should look like the picture above.
|
|
|
Now you are ready for the code. Select all of the following code (by clicking on the word 'Option' three times) and copy it to the clipboard [Ctrl][Insert]. Then paste it into the code window of Form1 with [Shift][Insert].
|
Option Explicit
Private Sub DBCombo1_Change()
Data1.RecordSource = "Select * From Customers Where " & _
"CompanyName Like """ & DBCombo1.Text & "*"""
Data1.Refresh
End Sub
|
|
Now just run the program and start typing into the DBCombo.
|