PDA

Click to See Complete Forum and Search --> : searching a db in vb with sql


pazza
Jul 28th, 2000, 03:49 AM
I have a databse which has a field called recipes. i want to be able to search for records which contain text which is given in a text box. All i can get it to do is find exact matches. waht i need is a command like "containg text" or wildcards but i cant figure it out. below is my sorce code so u know what im on about. Thanx.


Dim sql1, sql2, sql3 As String

Private Sub findcmd_Click()
If (sql1 = "") And (findtxt.Text = "") Then
Me.Hide
Else
sql2 = findtxt.Text
sql3 = "SELECT Recipes.RecipeName, Recipes.Ingredients, Recipes.Method From Recipes "
mainsql = sql3 + sql1 + [sql2] + "');"
frmMain.Adorecipe.RecordSource = mainsql
frmMain.Adorecipe.Refresh
Me.Hide
End If
End Sub

Private Sub Form_Load()
sql3 = "SELECT Recipes.RecipeName, Recipes.Ingredients, Recipes.Method From Recipes ORDER BY Recipes.RecipeName;"
frmMain.Adorecipe.RecordSource = sql3
sql1 = ""
End Sub

Private Sub indred_Click()
sql1 = "WHERE (recipes.ingredients ='"
recname.Enabled = False
findtxt.Text = ""
findtxt.Enabled = True
End Sub

Private Sub maincmd_Click()
frmMain.Show
Unload findfrm
End Sub

Private Sub recname_Click()
sql1 = "WHERE (recipes.recipename ='"
indred.Enabled = False
findtxt.Text = ""
findtxt.Enabled = True
End Sub

nevyn
Jul 28th, 2000, 05:40 AM
In the 'where'-clause of your query, you can use
like '*TextToFind*' instead of ='TextToFind'

Hope this helps