• Linking a text box with a combo box (XP)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Linking a text box with a combo box (XP)

    Author
    Topic
    #405781

    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

    Viewing 1 reply thread
    Author
    Replies
    • #836359

      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?

      • #836377

        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

        • #836381

          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.

        • #836382

          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.

        • #836547

          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.

        • #836548

          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.

      • #836378

        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

    • #836360

      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?

    Viewing 1 reply thread
    Reply To: Linking a text box with a combo box (XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: