vba和组合框 [英] vba and combo box

查看:142
本文介绍了vba和组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,你能帮我一个VB代码,用一个组合框从一张桌子上选择一条记录,然后把它显示在一个文本框上。
有一个是什么用于存储我想要销售的产品的表。在此表中,我有一个产品领域和一个价格领域;我想让组合框选择我的产品并在文本框中显示价格。我可以有这个向导,但它对我不起作用因为我想在这个表格上有6套组合和文字。
请帮助我。

Hi guys,
Can you please help me wirte a VB code to select a record from a table using a combo box, and display it on one text box.
What have is one table that is used to store my products that I want to sale. In this table I have a product field and a price field; and I want to have the combo box to select my product and display the price on the text box. I could have the wizard for this, but it is not working for me becouse I want 6 sets of combo and text on this form.
please help me.

推荐答案


  1. 您使用的是vba访问吗?然后按照以下步骤对您有所帮助。

  2. 根据您的解释,您需要显示产品列表的组合框和产品选择,它将在文本框中显示价格。

  3. First Set具有适用于您的适当查询的组合框的RowSource属性。

  4. 例如, RowSource ='SELECT [Product]。[ProductId],[Product]。[ProductName],[Product]。[ProductPrice] FROM Product ;'

  5. 在上面的查询中,我从产品表" ProductId "," ProductName "中取出三个字段, " ProductPrice "

  6. 设置 columnWidth 属性,如0"; 1"; 0",这将只显示"产品名称"在组合框中,其他两列名称将被隐藏,因为我们将列宽设置为0。

  7. 设置列数属性= 3.

  8. 设置绑定列 Property = 3,因为我们对产品价格感兴趣。因此,组合框将返回值 ProductPrice

  9. 现在捕获事件并更新文本框

  10. 私有Sub ComboProduct_AfterUpdate()
    TextBoxPrice.Value = ComboProduct.Value''''ComboProduct.value将在我们设置bound column = 3时返回产品价格。
    End Sub

  1. Are you using vba access ? Then follow below steps it will be helpful to you.
  2. As per your explanation, you need combo box which display product list and on selection of product it will show price in text box.
  3. First Set RowSource Property of combo box with appropriate query which is applicable to you.
  4. For example, RowSource = 'SELECT [Product].[ProductId], [Product].[ProductName], [Product].[ProductPrice] FROM Product;'
  5. in above query i am taking three field from product table "ProductId ","ProductName ","ProductPrice "
  6. Set columnWidth property like 0";1";0", this will display only "ProductName " in combo box other two column name will be hidden as we are setting column width with 0.
  7. Set column count property = 3.
  8. Set Bound Column Property = 3, as we are interested in product price. So combo box will return ProductPrice in value.
  9. Now capture event and update your text box
  10. Private Sub ComboProduct_AfterUpdate()
        TextBoxPrice.Value = ComboProduct.Value ''''ComboProduct.value will return product price as we set bound column =3 .
    End Sub

同样如果您需要显示产品的价格清单和选择价目表,您可以通过对约束列进行少量修改来捕获产品ID。

让我总结一下。
首先在 rowSource 中应用正确的查询,设置 columnWidth ,设置 ColumnCount ,设置 BoundColumn ,捕获更新后事件或任何其他适合您逻辑的事件并更改文本框值。

如果您有任何疑问,请告诉我。谢谢。

Same way if you need to show price list of product and on selection of price list you can capture product id , by doing little modification in bound column.

Let me summarize for you.
First apply proper query in rowSource ,Set columnWidth ,set ColumnCount ,Set BoundColumn , Capture the after update event or any other event which is suaitable to your logic and change the text box value.

Please let me know if you have any query. Thanks.


这篇关于vba和组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆