Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    5

    Lightbulb Unanswered: Searching Problem ...

    Iam using VB6 (ADO) & in back end Ms Access. I have two option buttons i.e optName & OptPhono.For performing search i use a cmdSearch
    button & a text box to write what i want to search.
    Both code for searching works fine but the problem is, i can choose only one code at a time.
    For example if i want to search name them i make remarks all the lines
    of Phono search which u can see below & vice virsa.
    Please can u guide me that how can i use both code under cmdSearch so that at run
    time if i want to perform search by clicking the OptName then i can do it &
    if i want to seacrh by Phono then i can choose the optPhono for seacrhning.
    One way is to do Case i.e

    case optNmae
    code
    Case OptPhone
    Code

    But iam unable to do it.please can u write the complete code to do with it or there
    is any other way to do it.
    Thanks a lot for the help.




    Private Sub cmdSearch_Click()
    Dim opt As String

    '--------------Code for Searching Name from Datdabase

    Set rec = cn.Execute("select * from student where Name LIKE '" & Text1.Text & "%'")
    If rec.BOF = True And rec.EOF = True Then
    MsgBox "record not found"
    Else
    txtRoll.Text = rec.Fields(0)
    txtName.Text = rec.Fields(1)
    txtFather.Text = rec.Fields(2)
    txtPhono.Text = rec.Fields(3)
    End If
    '--------------Code for Searching Phono from Datdabase

    Set rec = cn.Execute("select * from student where phono=" & opt1)
    If rec.BOF = True And rec.EOF = True Then
    MsgBox "record not found"
    Else
    txtRoll.Text = rec.Fields(0)
    txtName.Text = rec.Fields(1)
    txtFather.Text = rec.Fields(2)

    End If
    End sub

  2. #2
    Join Date
    Nov 2003
    Posts
    76
    strSql as string

    if optname then
    strsql="select * from student where Name LIKE '" & Text1. Text & "%'"
    else
    strsql="select * from student where phono=" & opt1
    end if

    if you want both then

    if optname=checked and optphono=checked then
    strsql= select * from student where Name LIKE '" & Text1. Text & "%'" & " AND Phono=" &opt1
    end if
    set rec=cn.execute(strsql)

    HTH.

Posting Permissions

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