|
小弟刚学treeview,调试时出现“要求对象”提示,不知道哪里出错了 !
代码如下:
Option Compare Database
Private Sub Form_Load()
Dim Conn As New ADODB.Connection '国家
Dim rs As New ADODB.Recordset '|_地区
Dim nodIndex As Node '|_企业
Dim sqlstr As String
Set Conn = CurrentProject.Connection
'设置国家
sqlstr = " Select Distinct 客户.国家编号,国家.国家 From 客户 Inner Join 国家 On 客户.国家编号 = 国家.国家编号;"
rs.Open sqlstr, Conn, adOpenKeyset, adLockPessimistic
rs.MoveFirst
With rs
Do While Not .EOF
Set nodIndex = TreeView1.Nodes.Add(, , "a" & Rec.Fields("国家编号"), Rec.Fields("国家"), 1, 2)
nodIndex.Sorted = True
.MoveNext
Loop
End With
rs.Close
'设置地区
sqlstr = "Select Distinct 客户.国家编号,客户.地区编号,客户.城市 From 客户 Inner Join 地区 On 客户.地区编号 = 地区.地区编号;"
rs.Open sqlstr, Conn, adOpenKeyset, adLockPessimistic
rs.MoveFirst
With rs
Do While Not .EOF
Set nodIndex = TreeView1.Nodes.Add("a" & Rec.Fields("国家编号"), tvwChild, "b" & rs.Fields(国家编号) & rs.Fields(地区编号), rs.Fields("城市"), 1, 2)
nodIndex.Sorted = True
.MoveNext
Loop
End With
rs.Close
'设置企业
sqlstr = "Select * From 客户 Order By 客户.简称"
rs.Open sqlstr, Conn, adOpenKeyset, adLockPessimistic
rs.MoveFirst
With rs
Do While .EOF
Set nodIndex = TreeView1.Nodes.Add("b" & rs.Fields(国家编号) & rs.Fields(地区编号), tvwChild, "c" & rs.Fields("客户编号"), rs.Fields("简称"), 1, 2)
nodIndex.Sorted = True
.MoveNext
Loop
End With
rs.Close
End Sub
注意:“客户”为主表,含国家编号,地区编号 字段;从表 “国家”“地区”,分含国家编号,地区编号 字段
[ 本帖最后由 ilikeu 于 2008-1-31 09:42 编辑 ] |
|