如何在MS Access中的表单中插入自定义(运行时)值

时间:2011-07-25 05:30:13

标签: ms-access

我在Microsoft Access中有2个表

1)包含列的SALES

产品和产品价格

2)包含列的STOCK

产品,价格和数量

我已经针对表SALES

创建了一个表单

我希望当我在产品列中输入产品名称时,它会自动从STOCKS表中获取我输入的产品的价格。

我可能要输入10个产品名称并添加每个产品的价格以获得TOTAL SALE值(我正在制作销售点系统)

如何实现

感谢

1 个答案:

答案 0 :(得分:0)

假设productField表单中有priceField个字段,您必须将此代码添加到on exit的{​​{1}}事件中

productField

你必须声明全局布尔变量If Not prodChanged Then exit sub ' if the user hasn't edited the product Dim recSet As Recordset Set recSet = CurrentDb.OpenRecordset("Select stock.price from stock where stock.product =" & Me.productField.Value) If Not recSet.EOF Then 'If the product exists Me.priceField = recSet.Fields(0) Else 'do default action End If podChanged=false 'reset the product editted state 初始化为prodChanged并在false true

中设置OnChange