我在Microsoft Access中有2个表
1)包含列的SALES
产品和产品价格
2)包含列的STOCK
产品,价格和数量
我已经针对表SALES
创建了一个表单我希望当我在产品列中输入产品名称时,它会自动从STOCKS表中获取我输入的产品的价格。
我可能要输入10个产品名称并添加每个产品的价格以获得TOTAL SALE值(我正在制作销售点系统)
如何实现
感谢
答案 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