Hi,
I have problem in deleting from TreeView.
The treeview in my application loads the position and reportsTo from database.
That is the treeview will have
General Manager
Sales Manager
Sales Assistant
Human Resource Manager
IT Manager
Now when one needs to delete a position all they do is select from the treeview,
e.g ITManager and click the delete button.
Now if the user tries to Delete Sales Manager it should give an error message that the Position
linked to Sales Manager, That is the Sales Assistant has to be deleted first.
And the same goes for deleting General Manager, the rest has to be deleted first.
Below is the Function :
Public Function DeletePosition() As Boolean
Dim cnn As cls_Sys_DB
Dim bExecuteOK As Boolean
Dim iPositionID As Integer
DeletePosition = False
Set cnn = New cls_Sys_DB
With frmMainForm.TreeView1.SelectedItem
iPositionID = Right(.Key, Len(.Key) - 4)
End With
cnn.Query = "delete from position where " & _
"position_id=" & iPositionID
bExecuteOK = cnn.Execute(False)
DeletePosition = bExecuteOK
If bExecuteOK Then
MsgBox "Position deleted successfully."
Else
MsgBox "Error in deleting positon.Please try again."
End If
Set cnn = Nothing
End Function
I have problem in deleting from TreeView.
The treeview in my application loads the position and reportsTo from database.
That is the treeview will have
General Manager
Sales Manager
Sales Assistant
Human Resource Manager
IT Manager
Now when one needs to delete a position all they do is select from the treeview,
e.g ITManager and click the delete button.
Now if the user tries to Delete Sales Manager it should give an error message that the Position
linked to Sales Manager, That is the Sales Assistant has to be deleted first.
And the same goes for deleting General Manager, the rest has to be deleted first.
Below is the Function :
Public Function DeletePosition() As Boolean
Dim cnn As cls_Sys_DB
Dim bExecuteOK As Boolean
Dim iPositionID As Integer
DeletePosition = False
Set cnn = New cls_Sys_DB
With frmMainForm.TreeView1.SelectedItem
iPositionID = Right(.Key, Len(.Key) - 4)
End With
cnn.Query = "delete from position where " & _
"position_id=" & iPositionID
bExecuteOK = cnn.Execute(False)
DeletePosition = bExecuteOK
If bExecuteOK Then
MsgBox "Position deleted successfully."
Else
MsgBox "Error in deleting positon.Please try again."
End If
Set cnn = Nothing
End Function