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\ project207 3.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").Va lue & Chr(9) & _
.Fields("fakulti").Value & Chr(9) & _
.Fields("jabatan").Value & Chr(9) & _
.Fields("tahun").Value & Chr(9) & _
.Fields("alamattetap").Val ue & Chr(9), x
.MoveNext
*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\
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
.Fields("namawaris").Value
.Fields("status").Value & Chr(9) & _
.Fields("alamatsemasa").Va
.Fields("fakulti").Value & Chr(9) & _
.Fields("jabatan").Value & Chr(9) & _
.Fields("tahun").Value & Chr(9) & _
.Fields("alamattetap").Val
.MoveNext
To clear your flex grid:
YourFlexGrid.Clear
YourFlexGrid.Clear
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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!
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!
ASKER
Close
Malaysia
Malaysia
To find names that have "bil" in them, use
WHERE YourNameField LIKE '%bil%'