Cyril Beki
Board Regular
- Joined
- Sep 18, 2021
- Messages
- 57
- Office Version
- 2016
- Platform
- Windows
When i double click the listbox, the data shown in textbox is not sorted well (Refer Image).
Based on the image 1st image, textbox 1 should be blank , only textbox 2 is populated
And for Image 2, it should doing the same things whereby Textbox 2 should be blank, only textbox 1 is populated
Combobox Change Code
Add Data Code
Populate Data from listbox to textbox Code
Based on the image 1st image, textbox 1 should be blank , only textbox 2 is populated
And for Image 2, it should doing the same things whereby Textbox 2 should be blank, only textbox 1 is populated
Combobox Change Code
VBA Code:
Private Sub ComboBox1_Change()
If ComboBox1.Value = "Section" Then
TextBox1.Enabled = True
TextBox2.Enabled = False
TextBox2.BackColor = &H8000000F
TextBox1.BackColor = &H8000000E
Me.TextBox2.text = ""
TextBox1.text = "Please Enter New Section Here"
End If
If ComboBox1.Value = "Machine" Then
TextBox1.Enabled = False
TextBox2.Enabled = True
TextBox1.BackColor = &H8000000F
TextBox2.BackColor = &H8000000E
Me.TextBox1.text = ""
TextBox2.text = "Please Enter New Machine Here"
End If
End Sub
Add Data Code
VBA Code:
Private Sub Add_Click()
Dim text As Object
Set text = Sheet2.Range("A50000").End(xlUp)
'Add Data
text.Offset(1, 0).Value = Me.ComboBox1.Value
text.Offset(1, 1).Value = Me.TextBox1.Value & Me.TextBox2.Value
On Error Resume Next
Me.ListBox1.RowSource = Sheet2.Range("Problem").Address(external:=True)
MsgBox ("Data is added succesfully")
'Clear form after add
Me.ComboBox1.Value = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
End Sub
Populate Data from listbox to textbox Code
VBA Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
On Error GoTo Error
With TextBox1
If .text = "Please Enter New Section Here" Then
.ForeColor = &H80000008 '<~~ Black Color
.text = ""
End If
End With
Me.ComboBox1.Value = Me.ListBox1.Column(0)
Me.TextBox1.Value = Me.ListBox1.Column(1)
With TextBox2
If .text = "Please Enter New Machine Here" Then
.ForeColor = &H80000008 '<~~ Black Color
.text = ""
End If
End With
Me.ComboBox1.Value = Me.ListBox1.Column(0)
Me.TextBox2.Value = Me.ListBox1.Column(1)
Attachments
Last edited: