【译文】如何从一个表中指定一个控件的值-周芳
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


【译文】如何从一个表中指定一个控件的值

发表时间:2013/9/3 9:04:27 评论(0) 浏览(12446)  评论 | 加入收藏 | 复制
   
摘 要:DLookup 函数用于从指定记录集(一个域)获取特定字段的值。可以在 Visual Basic、宏、查询表达式、窗体或报表上的计算控件中使用 DLookup 函数。
正 文:

来自:微软  翻译:周芳

【译文】如何从一个表中指定一个控件的值

      您可以使用DLookup函数来显示字段值不在记录来源表或报告。例如,假设您有一个基于订单详细信息的表。表显示了OrderID、ProductID,UnitPrice、Quantity和Discount字段。 然而,UnitPrice字段是在另一个产品表中。当用户选择一个产品,你可以使用DLookup函数在相同的表计算控制显示UnitPrice。


      下面的示例把当前选定的ProductID组合框中产品的价格填入到UnitPrice文本框。

VBA代码
Private Sub ProductID_AfterUpdate() 
 
’在传递给DLookup函数前评估过滤。

 strFilter = "ProductID = " & Me!ProductID 
 
’查找产品的单价将它赋值给UnitPrice控件。

 Me!UnitPrice = DLookup("UnitPrice", "Products", strFilter)
 
End Sub

 

      这个DLookup函数有三个参数。第一个参数指定要查找的字段(UnitPrice);第二个指定表(产品);第三个指定找到的值(与ProductID一样的当前记录在订单子表的ProductID值)。

 

原文:How to: Assign a Control a Value From a Table

      You can use the DLookup function to display the value of a field that is not in the record source for your form or report. For example, suppose you have a form based on an order Details table. The form displays the orderID, ProductID, UnitPrice, Quantity, and Discount fields. However, the UnitPrice field is in another table: Products. You could use the DLookup function in a calculated control to display the UnitPrice on the same form when the user selects a product.


      The following example populates the UnitPrice text box with the price of the product currently selected in the ProductID combo box.

 

 

VBA
Private Sub ProductID_AfterUpdate()
 
 ' Evaluate filter before it is passed to DLookup function. 
 strFilter = "ProductID = " & Me!ProductID
 
 ' Look up product's unit price and assign it to the UnitPrice control. 
 Me!UnitPrice = DLookup("UnitPrice", "Products", strFilter)
 
End Sub


      The DLookup function has three arguments. The first specifies the field you are looking up (UnitPrice); the second specifies the table (Products); and the third specifies which value to find (the value for the record where the ProductID is the same as the ProductID on the current record in the orders subform).

 

 


Access软件网交流QQ群(群号:198465573)
 
 相关文章
【译文】自动刷新链接 Microsoft Access 表  【周芳  2013/5/7】
【译文】如何取消事件  【周芳(转)  2013/5/21】
【译文】把DAO代码转化为ADO  【周芳(转)  2013/6/4】
【译文】如何防止在窗体上移动时意外清除数据  【周芳  2013/7/30】
【译文】当用户删除一条记录时,显示一个自定义的对话框  【周芳  2013/8/13】
【译文】如何为一个组合框或列表框添加全选按钮  【周芳  2013/8/27】
常见问答
技术分类
相关资源
文章搜索
关于作者

周芳

文章分类

文章存档

友情链接