SI ME PUEDEN AYUDAR A ENTENDER ESTE CODIGO LES AGRADECERIA MUCHO
Private Sub cmdLlenarTreeA()
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset
Dim SQLC, SQLC1, SQLC2, SQLC3 As String
SQLC = "select ACT_PERIOD from activida where ACT_COD IN (SELECT DISTINCT ACT_COD FROM ANTECEDE) GROUP BY ACT_PERIOD"
TreeView1.Nodes.Clear
Call IniciarConexionDBF
rs.Open SQLC, cnn, adOpenDynamic, adLockOptimistic
Do While Not rs.EOF
TreeView1.Nodes.Add , , "A" & rs(0), rs(0), ImageList1.ListImages("a").Key
SQLC1 = "select distinct ACT_TRIM from activida where ACT_PERIOD=" & rs(0) & " and ACT_COD IN (SELECT DISTINCT ACT_COD FROM ANTECEDE) order by ACT_TRIM"
rs1.Open SQLC1, cnn, adOpenDynamic, adLockOptimistic
Do While Not rs1.EOF
TreeView1.Nodes.Add "A" & rs(0), tvwChild, "A" & rs(0) & "T" & rs1(0), "TRIM " & rs1(0), ImageList1.ListImages("b").Key
SQLC2 = "select a.emp_ruc, a.act_cod, e.EMP_RSOCIA from activida a , EMPRESA e WHERE e.EMP_RUC = a.EMP_RUC and a.ACT_COD IN (SELECT DISTINCT ACT_COD FROM ANTECEDE) and (a.act_period=" & rs(0) & " and a.act_trim= " & rs1(0) & ") ORDER BY e.EMP_RSOCIA"
rs2.Open SQLC2, cnn, adOpenDynamic, adLockOptimistic
Do While Not rs2.EOF
TreeView1.Nodes.Add "A" & rs(0) & "T" & rs1(0), tvwChild, "V" & rs2(1) & "A" & rs(0) & "T" & rs1(0), rs2(2), ImageList1.ListImages("c").Key
SQLC3 = "select antec_titu, antec_cod, iif(antec_tip = '01', '(C)',iif(antec_tip = '02', '(N)','(A)')) from antecede where act_cod=" & rs2(1) & " order by 3"
rs3.Open SQLC3, cnn, adOpenDynamic, adLockOptimistic
Do While Not rs3.EOF
TreeView1.Nodes.Add "V" & rs2(1) & "A" & rs(0) & "T" & rs1(0), tvwChild, "Y" & rs3(1) & "V" & rs2(1) & "A" & rs(0) & "T" & rs1(0), rs3(2) & " " & rs3(0), ImageList1.ListImages("d").Key
rs3.MoveNext
Loop
rs3.Close
rs2.MoveNext
Loop
rs2.Close
rs1.MoveNext
Loop
rs1.Close
rs.MoveNext
Loop
Call Desconectar
End Sub