A
asukuo
Hi all.
I have follow situation:
- Sheet Customers
A B C D E
1 Id Name Address City Phone
2 1 Rose 7, Red St. Paris 123456
3 2 Lisa 2, Blue Av. Milan 789012
4 3 Tom 5, Pink St. Rome 452134
5 4 Sam 3, Green St. London 327812
etc.
I have UserForm1 with following controls:
- Listbox1 ( alphabet letters)
- Listbox2 ( name)
- Textbox1 (Address)
- Textbox2 (City)
- Textbox3 (Phone)
and this code:
Option Explicit
Private Sub Userform_Activate()
Worksheets("Customers").Activate
End Sub
Private Sub UserForm_Initialize()
m_FillAlphabet ListBox1
End Sub
Private Sub m_FillAlphabet(MiaLista As MSForms.ListBox)
' Populate listbox1 with alphabet letters (Capital)
Dim intIndice As Integer, intalfa As Variant
Const CAPITAL = 65
intalfa = CAPITAL
MiaLista.Clear
For intIndice = 1 To 26
MiaLista.AddItem Chr(intalfa)
intalfa = intalfa + 1
Next
End Sub
Private Sub m_FillNames(MatchNome As String, MiaLista As MSForms.ListBox)
' Populate listbox2 with Names corresponding to the selected letter of
alphabet
Dim lngRiga As Long
Dim strLettera As String
strLettera = Left(MatchNome, 1)
MiaLista.Clear
lngRiga = 2
With Worksheets("Customers")
Do While .Cells(lngRiga, 1) <> ""
If StrComp(strLettera, Left(.Cells(lngRiga, 2), 1), _
vbTextCompare) = 0 Then
MiaLista.AddItem .Cells(lngRiga, 2)
End If
lngRiga = lngRiga + 1
Loop
End With
End Sub
Private Sub ListBox1_Change()
' populate Listbox2 with Names and clear Textboxes
m_FillNames ListBox1.List(ListBox1.ListIndex), ListBox2
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub ListBox2_Click() ' here need your help
TextBox1.ControlSource = ? code for Address
TextBox2.ControlSource = " for City
TextBox3.ControlSource = " for phone
End Sub
Thanks for any help.
Regards, John.
I have follow situation:
- Sheet Customers
A B C D E
1 Id Name Address City Phone
2 1 Rose 7, Red St. Paris 123456
3 2 Lisa 2, Blue Av. Milan 789012
4 3 Tom 5, Pink St. Rome 452134
5 4 Sam 3, Green St. London 327812
etc.
I have UserForm1 with following controls:
- Listbox1 ( alphabet letters)
- Listbox2 ( name)
- Textbox1 (Address)
- Textbox2 (City)
- Textbox3 (Phone)
and this code:
Option Explicit
Private Sub Userform_Activate()
Worksheets("Customers").Activate
End Sub
Private Sub UserForm_Initialize()
m_FillAlphabet ListBox1
End Sub
Private Sub m_FillAlphabet(MiaLista As MSForms.ListBox)
' Populate listbox1 with alphabet letters (Capital)
Dim intIndice As Integer, intalfa As Variant
Const CAPITAL = 65
intalfa = CAPITAL
MiaLista.Clear
For intIndice = 1 To 26
MiaLista.AddItem Chr(intalfa)
intalfa = intalfa + 1
Next
End Sub
Private Sub m_FillNames(MatchNome As String, MiaLista As MSForms.ListBox)
' Populate listbox2 with Names corresponding to the selected letter of
alphabet
Dim lngRiga As Long
Dim strLettera As String
strLettera = Left(MatchNome, 1)
MiaLista.Clear
lngRiga = 2
With Worksheets("Customers")
Do While .Cells(lngRiga, 1) <> ""
If StrComp(strLettera, Left(.Cells(lngRiga, 2), 1), _
vbTextCompare) = 0 Then
MiaLista.AddItem .Cells(lngRiga, 2)
End If
lngRiga = lngRiga + 1
Loop
End With
End Sub
Private Sub ListBox1_Change()
' populate Listbox2 with Names and clear Textboxes
m_FillNames ListBox1.List(ListBox1.ListIndex), ListBox2
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub
Private Sub ListBox2_Click() ' here need your help
TextBox1.ControlSource = ? code for Address
TextBox2.ControlSource = " for City
TextBox3.ControlSource = " for phone
End Sub
Thanks for any help.
Regards, John.