Marcin
Marcin

Reputation: 33

Access VBA - TreeView Control - AfterLabelEdit Event

I've got a treeview control in my form. I would like to be able to edit the node in the tree and push the change to Access DB. However, I'm having trouble finding an appropriate event. MSDN treeview events reference page advices AfterLabelEdit, but I am not able to get it to work. Is anyone aware of any workaround/solution? Snippet of the code I use (I've added onClick and onDblClick for comparison, as they work):

Private Sub xMyTreeview_Click() 'OK
 testit
End Sub
Private Sub xMyTreeview_DblClick() 'OK
 EditLabel
End Sub

Private Sub xMyTreeview_AfterLabelEdit() 'Problem
 AfterLabel
End Sub

Sub EditLabel()
 Me.xMyTreeview.StartLabelEdit
End Sub

Sub AfterLabel()
 MsgBox prompt, vbOKOnly, "afterlabel"
End Sub

Sub testit()
 Dim nodSelected As MSComctlLib.Node ' a variable for the currently selected node

 Set nodSelected = Me.xMyTreeview.SelectedItem ' get the currently selected node

 NodesStrLength = Len(nodSelected.Key)
 Dim NodeStr As String
 Dim StrToChange As String
 StrToChange = nodSelected.Key
 NodeStr = Mid(StrToChange, 2, NodesStrLength - 1)

 Me.txtNodeID = NodeStr
 Me.sfrmDOCNODE.Visible = True
End Sub

Upvotes: 2

Views: 3139

Answers (1)

Alex K.
Alex K.

Reputation: 175826

Your link is to the .net Windows Form Treeview but MSComctlLib is the older Visual Basic Common Controls: http://msdn.microsoft.com/en-us/library/aa443023(v=vs.60).aspx

Note the event prototype is different; if you don't declare it with the correct arguments it will never get raised;

Private Sub object_AfterLabelEdit(cancel As Integer, newstring As String)

Upvotes: 1

Related Questions