在 VBA/Access 中更改记录时从当前记录中获取值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6898067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In VBA/Access get value from current record when changing records
提问by Mr_Chimp
I have an Access database. I have a map control embedded in a form (using MapInfo, but that's not important). When a user goes from one record to another I would like the map to re-centre on the appropriate coordinates. To do this I need to get the coordinates which are stored in the current row of the table which is the data source for the form. My question is how I access this value. This is pretty simple, right?
我有一个 Access 数据库。我有一个嵌入在表单中的地图控件(使用 MapInfo,但这并不重要)。当用户从一个记录转到另一个记录时,我希望地图重新以适当的坐标为中心。为此,我需要获取存储在表格当前行中的坐标,该表格是表单的数据源。我的问题是我如何访问这个值。这很简单,对吧?
I have worked out that the "On Current" event is triggered when the record is changed but I can't seem to refer to the xcoord and ycoord fields in the current row.
我已经发现当记录更改时会触发“On Current”事件,但我似乎无法引用当前行中的 xcoord 和 ycoord 字段。
This pageseems to suggest that I need to create a module to do this. Surely there's a simpler way?
此页面似乎表明我需要创建一个模块来执行此操作。肯定有更简单的方法吗?
Thanks in advance!
提前致谢!
Update: If I put a pair of textbox controls in the form that display the x and y coordinates then I can access them by doing Me.x_coord. Is this theanswer?
更新:如果我将一对文本框控件放在显示 x 和 y 坐标的表单中,那么我可以通过执行 Me.x_coord 来访问它们。这是答案吗?
回答by Banjoe
In Access VBA you can reference the fields of a bound form's recordsource with the syntax:
在 Access VBA 中,您可以使用以下语法引用绑定表单的记录源的字段:
Forms!your_form_name!your_field_name
In your case, you can grab the current x_coord
with Me!x_coord
. No need to bind it to a control to get the data.
在您的情况下,您可以x_coord
使用Me!x_coord
. 无需将其绑定到控件即可获取数据。