I use listview1 to display list of Fields name from a table. Now I add another listview2 to display fields name user select from listview1. I use listview1_doubleclick event to add item to listview2. Ok this part I done successfully.
Now I add record filtering section on my form and add cboFields, cboOperator and txtSearch. These 3 controls needed to create the sql query. Ok now when user select field eg. ID, operator eg. < and type 10 into txtSearch I have a complete sql query as follow
This is the code I use so farSELECT ID,NAME,ADDRESS FROM PATIENT WHERE ID < 10
VB Code:
Dim squery As String, sQuery1 As String, sString As String Dim iCount As Integer, jCount As Integer 'Add column headers base on user selection For iCount = 1 To lv2.ListItems.Count sString = sString + "," + lv2.ListItems.Item(iCount) Set iCol3 = lv3.ColumnHeaders.Add(, , lv2.ListItems.Item(iCount)) Next iCount 'Create a query record squery = "SELECT " & Mid(sString, 2, Len(sString)) & " FROM MAKLUMAT_RAWATAN " If cboFields = "Age" Then sQuery1 = "WHERE " & cboFields & " " & cboOperator & "" & txtSearch Else sQuery1 = "WHERE " & cboFields & " " & cboOperator & "'" & txtSearch & "'" End If 'Test if user use filtering or not If cboFields = "" Or cboOperator = "" Or txtSearch = "" Then squery = squery + sQuery1 Else squery = squery End If RS.Open squery, con, adOpenDynamic, adLockOptimistic 'Add Records (I Got problem here... How can I the query here?) For iCount = 0 To RS.RecordCount - 1 Set iItem3 = lv3.ListItems.Add(, , RS(0)) 'Id 'Add subitems For jCount = 1 To lv2.ListItems.Count - 1 iItem3.ListSubItems.Add , , RS(jCount) Next jCount RS.MoveNext Next iCount
As you can see the 'Add Records section, I have problem to use the sql query to populate listview3. Can anybody help![]()




Reply With Quote