+ Reply to Thread
Results 1 to 3 of 3

Select Row in List Box with 2 columns - Col 1 populates form 1 box1,Col 2 pop box2

  1. #1

    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


  2. #2
    Tom Ogilvy
    Guest

    Re: 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


    <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




  3. #3
    B
    Guest

    Re: 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.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1