Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > 综合其它

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

时 间:2013-09-03 09:04:27
作 者:周芳   ID:24526  城市:上海
摘 要: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群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助