Generate value in textbox based on combobox selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • extrym
    New Member
    • Jan 2010
    • 4

    Generate value in textbox based on combobox selection

    I created a product sales database which contains 4 tables. Two of those tables are Normal Transactions and Item.

    Normal Transactions
    normal_trans_ID
    item_ID
    item_qty
    item_cost
    total_cost
    item_date
    staff_ID

    Item

    item_ID
    item_name
    item_cost

    I've used the Lookup function for item_ID (in the table Normal Transactions) so that it displays the values found in item_ID (of the table Item). I've also created a form for Normal Transactions.

    item_ID (of the table Normal Transactions) is a combo box in the form Normal Transactions. item_cost (of the table Normal Transactions) is a text box, also in the form Normal Transactions.
    How do I make it so that when I select a value from the combo box item_ID, the value of item_cost (in the Item table) which corresponds to the value of selected item_ID, is generated in the text box item_cost (in the form Normal Transactions)?
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Add the item_cost as third row in the rowsource for the combobox.
    Next make sure that the number of columns in the Format tab is set to 3.
    Finally use this line of code in the AfterUpdate event of the combobox:
    Code:
    Me.[item_cost] = Me.item_id.column(2)
    The columns start at 0 so you need (2) and not (3) for the third column.

    Nic;o)

    Comment

    • extrym
      New Member
      • Jan 2010
      • 4

      #3
      It worked! I used (3) for the third column before, so that was the problem.
      Thanks for replying, Nico!

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        Glad I could teach you the "zero based" principle :-)

        Nic;o)

        Comment

        Working...