Results 1 to 2 of 2

Thread: searching a db in vb with sql

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    1
    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

  2. #2
    Junior Member
    Join Date
    Jul 2000
    Location
    Antwerp,Belgium
    Posts
    21
    In the 'where'-clause of your query, you can use
    like '*TextToFind*' instead of ='TextToFind'

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width