andresandres83
New Member
- Joined
- Jun 26, 2019
- Messages
- 3
Hello, I want to insert items in a list and for that I have put a text box inside a frame that I place over the desired item in the list. All this because you cannot put a textbox on a list in Zorder 0.
The operative to follow is: First you have to select an item from a list, then press the cmdAdd button to insert a new row. Then write in the created spaces and then click on any other element to trigger the events.
The results I get are not always the same, sometimes the ListBox_Exit event trigger first and sometimes the Frame_Exit. I cannot find the reason.
I send source code and screenshots of the userform with objects and results.
There must be data to fill the lists in the first 4 rows of columns A and B of Sheet1.
Input in Sheet1
userform with objets, names and properties
Results, 4 examples of random results
The operative to follow is: First you have to select an item from a list, then press the cmdAdd button to insert a new row. Then write in the created spaces and then click on any other element to trigger the events.
The results I get are not always the same, sometimes the ListBox_Exit event trigger first and sometimes the Frame_Exit. I cannot find the reason.
I send source code and screenshots of the userform with objects and results.
There must be data to fill the lists in the first 4 rows of columns A and B of Sheet1.
Code:
Option Explicit
Private mlngListIndex As Long
Private mbNotExecute As Boolean
Private Sub UserForm_Initialize()
With UserForm1.lstLeft
.List = Sheets("Sheet1").Range("A1:A4").Cells.Value2
End With
With UserForm1.lstRight
.List = Sheets("Sheet1").Range("B1:B4").Cells.Value2
End With
End Sub
Private Sub lstLeft_Click()
Debug.Print "lstLeft_Click"
If mbNotExecute Then Exit Sub
With UserForm1
If .fraLeft.Visible Then Exit Sub
mbNotExecute = True
.lstRight.ListIndex = .lstLeft.ListIndex
mbNotExecute = False
End With
End Sub
Private Sub lstRight_Click()
Debug.Print "lstRight_Click"
If mbNotExecute Then Exit Sub
With UserForm1
If .fraLeft.Visible Then Exit Sub
mbNotExecute = True
.lstLeft.ListIndex = .lstRight.ListIndex
mbNotExecute = False
End With
End Sub
Private Sub fraLeft_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Debug.Print "fraLeft_Exit"
End Sub
Private Sub fraRight_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Debug.Print "fraRight_Exit"
End Sub
Private Sub cmdAdd_Click()
With UserForm1
If .lstLeft.ListIndex <> -1 Then
.lstLeft.AddItem "", .lstLeft.ListIndex
.lstRight.AddItem "", .lstLeft.ListIndex - 1
.lstLeft.ListIndex = .lstLeft.ListIndex - 1
mlngListIndex = .lstLeft.ListIndex
Call Edit
End If
End With
End Sub
Private Sub Edit()
Dim ObjTop As Single
With UserForm1
If .lstRight.ListIndex <> -1 Then
ObjTop = .lstLeft.ListIndex * 10 + .lstLeft.Top + 1
.fraLeft.Visible = True
.fraLeft.ZOrder 0
.fraLeft.Top = ObjTop
.fraLeft.Left = .lstLeft.Left + 2
.fraLeft.Height = 10
.fraLeft.Width = .lstLeft.Width - 3
.txtLeft.Top = -3
.txtLeft.Left = -3
.txtLeft.Width = .fraLeft.Width + 3
.txtLeft.Height = 16
.txtLeft.Text = .lstLeft.List(.lstLeft.ListIndex)
.fraRight.Visible = True
.fraRight.ZOrder 0
.fraRight.Top = ObjTop
.fraRight.Left = .lstRight.Left + 2
.fraRight.Height = 12
.fraRight.Width = .lstRight.Width - 2
.fraRight.Height = 10
.txtRight.Visible = True
.txtRight.Top = -3
.txtRight.Left = -2
.txtRight.Width = .fraRight.Width + 2
.txtRight.Height = 16
.txtRight.Text = .lstRight.List(.lstRight.ListIndex)
End If
End With
End Sub
Input in Sheet1
userform with objets, names and properties
Results, 4 examples of random results