Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Vancouver, Canada
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Linking a text box with a combo box (XP)

    I'm creating a form on which I have linked two combo boxes. They are Categories and Products. I'm using the AfterUpdate event procedure on the categories combo box to have only the products in the category chosen show up in the products combo box. Now I would like to add a text box (or label) to the mix. I would like the textbox to automatically reflect the Product ID of the product that is chosen from the products combo box. I would also like to have it so users cannot change the product ID here...it's for display purposes one (and ultimately I would like it to update a table called "Inventory Transactions")

    Any suggestions?

    Thanks,

    Christa

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Linking a text box with a combo box (XP)

    Assuming that the combo box has ProductID as its first column, probably hidden by setting its column width to 0, you can set the Control Source of the text box to

    =[ComboBoxName].[Column](0)

    This will automatically lock the text box.

    About your ultimate goal: is Inventory Transactions the record source of the form?

  3. #3
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Vancouver, Canada
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Linking a text box with a combo box (XP)

    The Products combo box gets it's selection from the AfterUpdate procedure which is as follows
    Private Sub Categories_AfterUpdate()
    Me.Products.RowSource = "SELECT Description FROM" & _
    " Inventory WHERE CategoryID = " & Me.Categories & _
    " ORDER BY Description"
    Me.Products = Me.Products.ItemData(0)
    End Sub

    How do I get Product ID into a second column this way. I've tried specifying 2 columns in the properties but that just give me the description and a blank column.

    Thanks,

    Christa

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Linking a text box with a combo box (XP)

    Set Column Count to 2, and set the column widths to 0;1 or something like that.
    Change the code to

    Me.Products.RowSource = "SELECT ProductID, Description FROM" & _
    " Inventory WHERE CategoryID = " & Me.Categories & _
    " ORDER BY Description"

    This will make ProductID the first, invisible column, and Description the second, visible column.

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Linking a text box with a combo box (XP)

    Once you have the Product ID in the first column of the combo box, you probably don't need the text box any more, (unless you particularly want to see it on the screen). For any other actions where you want to use the Product ID, such as InventoryTransfer, you can just use the combo as its value is the hidden Product ID.
    Regards
    John



Posting Permissions

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