Consulting

Results 1 to 6 of 6

Thread: Select a record from a combobox and add data to to the selected record row.

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    14
    Location

    Select a record from a combobox and add data to to the selected record row.

    Hi all.

    I have a user form with two list boxes and two text boxes. On the first list box one can select a "Safety Hazard". Based on that particular selection one can select "Proposed Actions" on the second listbox. The "Actual Actions" and "Date Complete" text boxes are there for user input. All that works fine.

    What I want to do is to add two records on the same spread sheet row as the selected "Proposed Actions". In other words, the selected "Proposed Actions" have data in column A10:E10 and I want to add data in column F10 "Actual Actions" & G10 "Date Complete" I don't know how to send the data to the right row for the row number will change depending on the selection made in the "Proposed Actions" list box.

    Thanks

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Use the ListIndex property to determine which one was selected. Since the list is 0 based, adjust your row computation accordingly.

  3. #3
    VBAX Regular
    Joined
    Dec 2008
    Posts
    14
    Location
    I was away for a while but am back into it again. Thanks for your suggestion but I think my explanation of the problem wasn't very clear. Let me try again.

    The following code is to populate the second combo box dropdown list so that the user can pick an item.

    [VBA]Private Sub ComboBox1_Change()
    Dim JSAFileName
    Dim JSAFileNameValue As String
    Dim tmpCell As String
    Dim PropRiskScoreCount As Integer

    ReDim PropRiskScore(0)
    PropRiskScore(0) = ""
    PropRiskScoreCount = 0
    JSAFileNameValue = CorrActForm1.ComboBox1.Value

    For Each JSAFileName In Worksheets("JSA DATA").Range("C2", "C" & ActiveCell.SpecialCells(xlLastCell).Row)
    If JSAFileName.Value = JSAFileNameValue Then
    PropRiskScore(PropRiskScoreCount) = JSAFileName.Offset(0, 8)
    PropRiskScoreCount = PropRiskScoreCount + 1
    ReDim Preserve PropRiskScore(UBound(PropRiskScore) + 1)
    End If
    Next JSAFileName

    CorrActForm1.ComboBox2.Enabled = True
    CorrActForm1.ComboBox2.List() = PropRiskScore

    End Sub[/VBA]

    This works fine. What I am struggling with is, once the user selects an item on the combo box list he can go the next textbox on the form and type e.g. "PPE" (Updating the Database). The textbox value "PPE" must then be entered on the same database row as the selected list item but 4 columns down. I don't know how to force the textbox value into that particular position.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    When you click the combobox, you need to save the ListIndex property to a variable. When you complete the Textbox, you can use that saved value to set the destination row. Can you post a sample workbook?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Dec 2008
    Posts
    14
    Location
    Hi mdmackillop.
    Attached is a copy of the file. When opening the file, select the "JSA Corrective Action Completion" button and from there select "JSA File Name" and then "Controlle Proposed Measure". The "Actual Corrective Action" and "Date Completed" are the fields that I want save to the database.

    Thanks

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    As you have repeating values in Column E, you cannot use the combobox index to locate the destination. I think you just need to cancel the selection of cell A1 and use the activecell row.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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