Link to home
Start Free TrialLog in
Avatar of winson
winson

asked on

SQL Problem and clearing FlexGrid

I have problem search an name that been enter and list out the name in that consist a particular string such as
 *bil*
How do we do this in SQL ? Following Are my source code

One more thing is how do i clear the FlexGrid if i like to empty it
 
Dim daorst As Recordset
Dim daodb As Database
Dim sSql As String
Dim x As Long
Set daodb = OpenDatabase("C:\Program Files\DevStudio\VB\TK2073\project2073.mdb")
sSql = "SELECT * FROM Makpel" & _
       " WHERE Makpel.nama = " & _
       Chr(34) & nama_s & Chr(34) & _
       " OR Makpel.nomatriks = " & _
       Chr(34) & nomatriks_s & Chr(34) & _
       " OR Makpel.alamatsemasa = " & _
       Chr(34) & alamat_s & Chr(34) & _
       " OR Makpel.namawaris = " & _
       Chr(34) & namawaris_s & Chr(34) & _
       " ORDER BY nama;"
Set daorst = daodb.OpenRecordset(sSql)
      With daorst
         Do While Not .EOF
         x = x + 1
         MSFlexGrid.AddItem .Fields("nama").Value & Chr(9) & _
         .Fields("nomatriks").Value & Chr(9) & _
         .Fields("namawaris").Value & Chr(9) & _
         .Fields("status").Value & Chr(9) & _
         .Fields("alamatsemasa").Value & Chr(9) & _
         .Fields("fakulti").Value & Chr(9) & _
         .Fields("jabatan").Value & Chr(9) & _
         .Fields("tahun").Value & Chr(9) & _
         .Fields("alamattetap").Value & Chr(9), x
         .MoveNext
Avatar of caraf_g
caraf_g

Half an answer:

To find names that have "bil" in them, use

WHERE YourNameField LIKE '%bil%'
To clear your flex grid:

YourFlexGrid.Clear
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of winson

ASKER

the problem is that the nama_s in my sql is a variable
so if i  WHERE Makpel.nama Like '*nama_s*' it does NOT work
but if i WHERE Makpel.nama Like '*bil*' it's  working
and list all the word with *bil*
but the fact is nama_s = bil
pls HELP
Use a string variable

Dim strSQLWhere As String

strSQLWhere = "WHERE Makpel.nama Like '*" & nama_s & "*'"

Good luck.

PS - just out of curiosity... what country are you from? I'm trying to guess but my best guess is Indonesia, please forgive me if I'm wrong!
Avatar of winson

ASKER

Close
Malaysia