If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Searching Problem ...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-04, 22:36
gardenair gardenair is offline
Registered User
 
Join Date: Jan 2004
Posts: 5
Lightbulb 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
Reply With Quote
  #2 (permalink)  
Old 01-26-04, 11:06
sivaroo sivaroo is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On