End If
rst.MoveNext
Loop
On Error Resume Next
Application.CommandBars("menuTreeView").Delete
Dim iBar As CommandBar
Dim iButton As CommandBarButton
Dim iCombo As CommandBarComboBox
Set iBar = Application.CommandBars.Add(Name:=("menuTreeView"), Position:=msoBarPopup, Temporary:=True)
With iBar
Set iButton = .Controls.Add(Type:=msoControlButton)
iButton.Caption = "增加 选定节点子节点(&A)"
iButton.OnAction = "Get_rmTreeView_PopupSelection"
iButton.Tag = "Add"
iButton.FaceId = 240
Me.TreeView0.Nodes(1).Expanded = True
'Me.TreeView0.EnsureVisible
End Sub
Private Sub TreeView0_NodeClick(ByVal node As Object)
Dim strCARGOTYPE_NO As String
Dim strSQL As String
Dim i As Integer
Dim n As Integer
Dim strTip As String
strCARGOTYPE_NO = Right(node.Key, Len(node.Key) - 3)
'判断是否是顶层
If strCARGOTYPE_NO = "1" Then '预先定义好的:NO.1,第3位向后的字符,所以是1
strSQL = "SELECT * FROM Ylxx;"
' Dim i As Long
Me![Text01] = node.Index
Me.lblTip.Caption = "物料分类"
Else
'i = Len(strCARGOTYPE_NO)
strSQL = "SELECT * FROM Ylxx WHERE left([CARGO_TYPE]," & i & ")='" & strCARGOTYPE_NO & "';"
Dim strCode() As String
Dim NodeID2 As String
strCode = Split(node.Key, ".")
NodeID2 = strCode(UBound(strCode))
Me![Text01] = node.Index
'Debug.Print I
For n = 1 To i / perSectionLong
strTip = strTip & Trim(CurrentDb.OpenRecordset("SELECT CARGOTYPE_BM FROM Ylfl where left([CARGOTYPE_NO]," _
& (n * perSectionLong) & ")='" & Left(strCARGOTYPE_NO, (n * perSectionLong)) & "' and CARGOTYPE_LEVEL=" & n & ";")(0).Value) & ">>"
Next
' strTip = "物料分类" & ">>" & Left(strTip, Len(strTip) - 2)
Me.lblTip.Caption = strTip
End If
'Debug.Print strSQL
Me.Yl.Form.RecordSource = strSQL
'Me.产品1.Form.RecordSource = strSQL
Me.Form.FilterOn = True
Me.Form.Filter = strSQL
End Sub
Private Sub treeview0_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Long, ByVal Y As Long)
Dim mNode As node
Dim NodeID As String
Dim strCode() As String
Dim strSQL As String
Dim rst As DAO.Recordset
Set mNode = TreeView0.SelectedItem
Dim i As Integer
strCode = Split(mNode.Key, "_")
NodeID = strCode(UBound(strCode))
'If blNodeClick Then
If Button = 2 Then ' 鼠标右键 点击 TreeView的Node
iSQLs = "" '公用变量
Dim combo As CommandBarControl
Set combo = CommandBars("menuTreeView").FindControl(Tag:="FIND")
' combo.Text = ""
Application.CommandBars("menuTreeView").ShowPopup
Select Case UCase(iSQLs) '公用变量 iSQLs 的值由CommandBars("menuTreeView").ShowPopup的指定宏返回
Case "ADD"
Call addCARGOTYPE
Case "del"
Call delCARGOTYPE
Case "NEXT"
Call popFIND(mNode, Trim(combo.Text), False)
''Case findA
Case "FIND"
If Trim(combo.Text) <> "" Then
Me.Painting = False
DoCmd.Hourglass True
Call popFIND(mNode, Trim(combo.Text), False)
With combo
Dim listFound As Boolean
If .ListCount > 0 Then
For i = 1 To .ListCount
If .List(i) = .Text Then
listFound = True
End If
Next
End If
If listFound = False Then .AddItem .Text
End With
Me.Painting = True
DoCmd.Hourglass False
End If
End Select
End If
End Sub
Function popFIND(NodeX As node, findText As String, blnFound As Boolean)
If blnFound = True Then Exit Function
Dim i As Integer
On Error Resume Next
' tj = Nz(Me.Text27, 0)
'If Nz(Me.Text27, 0) = 0 Then Exit Sub
For i = Inti + 1 To Me.TreeView0.Nodes.Count
If Me.TreeView0.Nodes(i).Text Like "*" & Trim(findText) & "*" Then
Me.TreeView0.Nodes(i).Selected = True
Me.TreeView0.SetFocus
TreeView0_NodeClick Me.TreeView0.SelectedItem
Inti = i
Exit Function
End If
Inti = i
Next
If Inti = Me.TreeView0.Nodes.Count Then
Inti = 1
MsgBox "没有了"
Exit Function
End If
'If NodeX.Children = 0 Then Exit Function
' Dim i As Long
' strCode = Split(NodeX.Key, ".")
' NodeID = strCode(UBound(strCode))
' Dim childNode As node
'If InStr(1, NodeX.Text, findText, vbTextCompare) > 0 Then
'NodeX.Selected = True
'If NodeX.Index > 1 Then NodeX.Parent.Expanded = True
' blnFound = True
'Exit Function
' End If
' Set childNode = NodeX.Child
' For i = 1 To NodeX.Children
' Call popFIND(childNode, findText, blnFound)
' Set childNode = childNode.Next
' Next