pupuchcha
Thành viên mới

- Tham gia
- 21/4/24
- Bài viết
- 6
- Được thích
- 1
em có dùng treeview để tạo biểu đồ cây và muốn viết code để khi nhấp vào phần con trong biểu đồ cây thị nội dung từ sheet sẽ hiện lên nhưng code em bị lỗi như thế này ạ. Mong mọi người giúp đỡ em ạ

Đây là code của em ạ, phần gạch dưới là phần hiện lỗi nhưng em không biết phải sửa thế nào ạ
Private Sub UserForm_Initialize()
Me.TreeView1.Nodes.Add Key:="BH", Text:="BAN HANG"
Me.TreeView1.Nodes.Add Key:="MH", Text:="MUA HANG"
Me.TreeView1.Nodes.Add Key:="BN", Text:="BIEN NHAN"
Me.TreeView1.Nodes.Add Key:="TT", Text:="THANH TOAN"
Me.TreeView1.Nodes.Add "BH", tvwChild, "BHCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "BH", tvwChild, "BHTM", "TIEN MAT"
Me.TreeView1.Nodes.Add "MH", tvwChild, "MHCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "MH", tvwChild, "MHTM", "TIEN MAT"
Me.TreeView1.Nodes.Add "BN", tvwChild, "BNCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "BN", tvwChild, "BNTM", "TIEN MAT"
Me.TreeView1.Nodes.Add "TT", tvwChild, "TTCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "TT", tvwChild, "TTTM", "TIEN MAT"
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim RNG As Long
Dim mKey, mParent As String
Dim SHT As Worksheet
Set SHT = Sheets (“Database”)
Me.ListBox1.Clear
Me.ListBox1.AddItem
For x = 0 To 8
Me.ListBox1.List(0, x) = SHT.Cells(1, x + 2)
Next x
Me.ListBox1.Selected(0) = True
RNG = SHT.range(“A2”) .CurrentRegion.Rows.Count
mKey = Left (Node.Key, 4)
mParent = Node.Parent
For I = 1 To RNG
If mkey = sht.Cells (I, “I”) And mParent = SHT.Cells(I, “C”) Then
Me.ListBox1.AddItem SHT.Cells(I, “B”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 1) = SHT.Cells(I, “C”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 2) = SHT.Cells(I, “D”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 3) = SHT.Cells(I, “E”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 4) = SHT.Cells(I, “F”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 5) = SHT.Cells(I, “G”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 6) = SHT.Cells(I, “H”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 7) = SHT.Cells(I, “I”)
End If
Next I
End Sub

Đây là code của em ạ, phần gạch dưới là phần hiện lỗi nhưng em không biết phải sửa thế nào ạ
Private Sub UserForm_Initialize()
Me.TreeView1.Nodes.Add Key:="BH", Text:="BAN HANG"
Me.TreeView1.Nodes.Add Key:="MH", Text:="MUA HANG"
Me.TreeView1.Nodes.Add Key:="BN", Text:="BIEN NHAN"
Me.TreeView1.Nodes.Add Key:="TT", Text:="THANH TOAN"
Me.TreeView1.Nodes.Add "BH", tvwChild, "BHCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "BH", tvwChild, "BHTM", "TIEN MAT"
Me.TreeView1.Nodes.Add "MH", tvwChild, "MHCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "MH", tvwChild, "MHTM", "TIEN MAT"
Me.TreeView1.Nodes.Add "BN", tvwChild, "BNCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "BN", tvwChild, "BNTM", "TIEN MAT"
Me.TreeView1.Nodes.Add "TT", tvwChild, "TTCK", "CHUYEN KHOAN"
Me.TreeView1.Nodes.Add "TT", tvwChild, "TTTM", "TIEN MAT"
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Dim RNG As Long
Dim mKey, mParent As String
Dim SHT As Worksheet
Set SHT = Sheets (“Database”)
Me.ListBox1.Clear
Me.ListBox1.AddItem
For x = 0 To 8
Me.ListBox1.List(0, x) = SHT.Cells(1, x + 2)
Next x
Me.ListBox1.Selected(0) = True
RNG = SHT.range(“A2”) .CurrentRegion.Rows.Count
mKey = Left (Node.Key, 4)
mParent = Node.Parent
For I = 1 To RNG
If mkey = sht.Cells (I, “I”) And mParent = SHT.Cells(I, “C”) Then
Me.ListBox1.AddItem SHT.Cells(I, “B”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 1) = SHT.Cells(I, “C”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 2) = SHT.Cells(I, “D”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 3) = SHT.Cells(I, “E”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 4) = SHT.Cells(I, “F”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 5) = SHT.Cells(I, “G”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 6) = SHT.Cells(I, “H”)
Me.ListBox1.List (Me.ListBox1.ListCount – 1, 7) = SHT.Cells(I, “I”)
End If
Next I
End Sub