|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我在ACCESS的一个窗体中加入了TREEVIEW控件,打开窗体后直接关闭数据库时总会出现BUG:key is not unique in collection,但是我仔细查了自己的代码,Treeview控件的节点KEY绝对没有重复的,我实在想不出问题出在哪里,谁能帮我想想是否还有其它原因?谢谢! 代码如下:
Private Sub Form_Load()
Dim strsql As String
Dim tv As TreeView
Dim nod1 As Node
Dim nod2 As Node
Dim rs As Recordset
Dim fldno As Integer, row As Integer, i As Integer, k As Integer
strsql = "select * from Catalog_Main_Form_List"
Set rs = CurrentDb.OpenRecordset(strsql)
fldno = rs.Fields.Count
For i = 0 To fldno - 1
Set tv = tv_main_form_list.Object
Set nod1 = tv.Nodes.Add(, , "root" & i + 1)
nod1.Text = rs.Fields(i).Name
nod1.ForeColor = vbBlue
rs.MoveFirst
k = 1
Do While Not rs.EOF
If rs.Fields(i).Value <> "" And Not IsNull(rs.Fields(i).Value) Then
Set nod2 = tv.Nodes.Add(nod1.key, tvwChild, "subroot" & i + 1 & "-" & k)
nod2.Text = rs.Fields(i).Value
k = k + 1
End If
rs.MoveNext
Loop
nod1.Expanded = True
Next i
rs.Close
Set rs = Nothing
'DoCmd.Maximize
End Sub
[ 本帖最后由 Monicazhang 于 2009-11-27 15:50 编辑 ] |
|