Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings!

currently working in two checklistbox one is Area chklistbox 1 and sub area chklistbox 2.

i successfully popoulate the area from chklistbox 1 when i check one or two area from chklistbox1 all the sub area will populate in the sub area checklistbox 2. Which i also manage to do it. However my problem now is when i unchecked the selected Area. i need to remove all the sub areas related to that area.

below are my codes.

Your all help is greatly appreciated and needed.

VB
Sub ListSubArea
        Dim rs,sql, i, j, areaname

        for i = 0 to chklistarea.Items.Count-1
             If chklistarea.Checked(i) = True then
                'chklistsubarea.items(j) = chklistarea.Checked(i)
               areaname = chklistarea.Items(i)
               End if
         Next

                set rs=createobject("adodb.recordset")
                sql = "SELECT * FROM v_area_subarea where c_area_name ='"& arename &"' order by c_sub_area_name"
                openrs rs,sql

                chklistsubarea.Clear

                if not rs.eof then
                    do
                     chklistsubarea.Items.Add rs.Fields("c_sub_area_name").Value
                     rs.movenext
                    loop until rs.eof
                End if

        rs.close

End Sub
Posted
Updated 31-Jan-12 19:33pm
v2

You already doing it. Below code will remove all the items in the Sub Area checkbox list.

VB
chklistsubarea.Clear()



Quick Question:
.NET has a very powerful DB concepts (ADO.NET), but you still using ADODB?
 
Share this answer
 
Comments
ambuenaventura 1-Feb-12 2:16am    
hi thank you for your reply. actually the application that I'm using is SalesLogix and the back-end side the approach code is similar to vb code.

What i need to do is Remove the data in chklistbox2 that is only related to checklistbox1.

please help. your inputs will highly appreciated. thanks
hi thank you for your reply. actually the application that I'm using is SalesLogix and the back-end side the approach code is similar to vb code. What i need to do is Remove the data in chklistbox2 that is only related to checklistbox1. please help. your inputs will highly appreciated. thanks
 
Share this answer
 
Done it's working now using below codes: :)

Sub ListSubArea

        dim rs
        dim sql
        dim i
        dim areaname


        areaname = ""
        chklistmainagent.Clear

        for i = 0 to chklistarea.Items.Count-1
             If chklistarea.Checked(i) = True then
               areaname =  Areaname & "'" & chklistarea.Items(i) & "',"
             End if
         Next

            if areaname <> "" then
                areaname = left(areaname,len(areaname)-1)
            Else
                chklistsubarea.Clear
                Exit sub
            End if

           set rs=createobject("adodb.recordset")
                sql = "SELECT * FROM v_area_subarea where c_area_name in ("& areaname &") order by c_sub_area_name"
                openrs rs,sql

                chklistsubarea.Clear

                if not rs.eof then
                    do
                     chklistsubarea.Items.Add rs.Fields("c_sub_area_name").Value

                     rs.movenext
                    loop until rs.eof
                End if

        rs.close

End Sub
 
Share this answer
 
v3
Sub ListSubArea

        dim rs
        dim sql
        dim i
        dim j
        dim areaname


        areaname = ""
        chklistmainagent.Clear

        for i = 0 to chklistarea.Items.Count-1
             If chklistarea.Checked(i) = True then
               areaname =  Areaname & "'" & chklistarea.Items(i) & "',"
             End if
         Next

            if areaname <> "" then
                areaname = left(areaname,len(areaname)-1)
            Else
                chklistsubarea.Clear
                Exit sub
            End if

           set rs=createobject("adodb.recordset")
                'sql = "SELECT * FROM v_area_subarea where c_area_name ='"& areaname &"' order by c_sub_area_name"
                sql = "SELECT * FROM v_area_subarea where c_area_name in ("& areaname &") order by c_sub_area_name"
                'msgbox areaname
                openrs rs,sql

                chklistsubarea.Clear

                if not rs.eof then
                    do
                     chklistsubarea.Items.Add rs.Fields("c_sub_area_name").Value

                     rs.movenext
                    loop until rs.eof
                End if

        rs.close

End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900