Select Row in List Box with 2 columns - Col 1 populates form 1 box1,Col 2 pop box2
Hi my first post. great resource.
This is my first real VB project. Please dont laugh at my code. Im a newbie. :) The part I cant figure out is this: These are the relevant objects: Form 1 (ufCombIns) has a commandbutton1 - click this and it opens Form 2 Form 1 has textbox(tbxOcCat) and a combobox (cbxOcCat) (among many other things) Form 2 (ufOcCat) has a list box (lbxOcCat) with 2 columns!!! This contains a 2 column range from a worksheet(OcCat!). The user selects (double clicks) the relevent row in lbxOcCat.... and this is the part Im having difficulty with.... The info in ufOcCat column1 should go to ufCombIns, tbxOcCat and ufOcCat column2 goes to ufCombIns, cbxOcCat and ufOcCat is closed. This is what I have so far...... (Some of this relates to the search function for lbxOcCat - just ignore cause that bit works...) Private Sub cmdLookUp_Click() Unload Me End Sub Private Sub TextBox1_Change() Dim s As String Dim i As Integer s = TextBox1.Text lbxOcCat.ListIndex = -1 If TextBox1.Text = "" Then Exit Sub End If For i = 0 To lbxOcCat.ListCount - 1 If UCase(lbxOcCat.List(i)) Like UCase(s & "*") Then lbxOcCat.ListIndex = i Exit Sub End If Next End Sub Private Sub UserForm_Initialize() lbxOcCat.RowSource = "OcCat!A2:B895" End Sub Private Sub lbxOcCat_DblClick(ByVal Cancel As MSForms.ReturnBoolean) If lbxOcCat.ListIndex = -1 Then Exit Sub End If Selection.Cells(1) = 'ufCombIns.tbxOcCat Selection.Cells(1).Offset(0, 1) = 'ufCombIns.cbxOcCat Unload Me End Sub |
Select Row in List Box with 2 columns - Col 1 populates form 1 box1,Col 2 pop box2
Private Sub lbxOcCat_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
If lbxOcCat.ListIndex = -1 Then Exit Sub End If With me.lbxOcCat ufCombIns. tbxOcCat.Value = .List(.ListIndex,0) ufCombIns.cbxOcCat.Value = .List(.listIndex,1) End With Unload Me End Sub -- Regards, Tom Ogilvy wrote in message ups.com... Hi my first post. great resource. This is my first real VB project. Please dont laugh at my code. Im a newbie. :) The part I cant figure out is this: These are the relevant objects: Form 1 (ufCombIns) has a commandbutton1 - click this and it opens Form 2 Form 1 has textbox(tbxOcCat) and a combobox (cbxOcCat) (among many other things) Form 2 (ufOcCat) has a list box (lbxOcCat) with 2 columns!!! This contains a 2 column range from a worksheet(OcCat!). The user selects (double clicks) the relevent row in lbxOcCat.... and this is the part Im having difficulty with.... The info in ufOcCat column1 should go to ufCombIns, tbxOcCat and ufOcCat column2 goes to ufCombIns, cbxOcCat and ufOcCat is closed. This is what I have so far...... (Some of this relates to the search function for lbxOcCat - just ignore cause that bit works...) Private Sub cmdLookUp_Click() Unload Me End Sub Private Sub TextBox1_Change() Dim s As String Dim i As Integer s = TextBox1.Text lbxOcCat.ListIndex = -1 If TextBox1.Text = "" Then Exit Sub End If For i = 0 To lbxOcCat.ListCount - 1 If UCase(lbxOcCat.List(i)) Like UCase(s & "*") Then lbxOcCat.ListIndex = i Exit Sub End If Next End Sub Private Sub UserForm_Initialize() lbxOcCat.RowSource = "OcCat!A2:B895" End Sub Private Sub lbxOcCat_DblClick(ByVal Cancel As MSForms.ReturnBoolean) If lbxOcCat.ListIndex = -1 Then Exit Sub End If Selection.Cells(1) = 'ufCombIns.tbxOcCat Selection.Cells(1).Offset(0, 1) = 'ufCombIns.cbxOcCat Unload Me End Sub |
Select Row in List Box with 2 columns - Col 1 populates form 1 box1,Col 2 pop box2
Your a legend Tom.
And a prolific problem solver. Thanks heaps. |
All times are GMT +1. The time now is 12:57 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com