Access 2010 表达式生成器

发布于 2025-01-05 02:40:42 字数 230 浏览 3 评论 0原文

我想要一个文本框包含基于 2 个其他控制字段值进行计算的数据 - 仅当其值为空时(即数据库中列的当前值为空)。

因此,我在默认值属性的表达式生成器中输入 =([control1]*[Control2])/1000 - 但结果始终显示文本框为空(即使 control2 和 control2 包含值)。

我怎样才能实现这个目标?这样的操作只能在代码隐藏即VB中完成吗?

谢谢,

KS

I want a text box to contain data which is a calculation based on 2 other control field values - only if it's value is null (ie the current value of the column in the database is null).

So I entered =([control1]*[Control2])/1000 in the expression builder for the default value property - however the result always shows the textbox to be empty (even tho control2 and control2 contain values).

How can I achieve this? Can such an operation only be done in code-behind ie VB??

thanks,

KS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红玫瑰 2025-01-12 02:40:42

我认为您正在谈论绑定到表单记录源中的字段的控件。当基础字段为 Null 时,您希望控件加载您的计算值。

如果该解释正确,您可以通过表单的 On Current 事件来执行此操作。

If IsNull(Me.txtYourTextBox) Then
    Me.txtYourTextBox = (Nz(Me.control1) * Nz(Me.Control2)) / 1000
End If

这会将计算的值加载到文本框中,允许用户根据需要更改其值,并在保存记录时将该值存储到绑定字段。

如果绑定字段不为 Null,则其值将显示在文本框中,而不会被 On Current 代码更改。

这就是你想要的吗?

I think you're talking about a control bound to a field in the form's record source. And when the underlying field is Null, you want the control loaded with your calculated value.

If that interpretation is correct, you can do it from the form's On Current event.

If IsNull(Me.txtYourTextBox) Then
    Me.txtYourTextBox = (Nz(Me.control1) * Nz(Me.Control2)) / 1000
End If

That will load the computed value into the text box, allow the user to change its value if desired, and store the value to the bound field when the record is saved.

If the bound field is not Null, its value will be displayed in the text box without alteration by the On Current code.

Is that what you want?

折戟 2025-01-12 02:40:42

要使用 VBA 完成此操作,请添加 Form_Load 事件。 (在“设计视图”中打开表单,在“表单属性”中单击“事件”选项卡,然后为“加载时”选择“事件过程”​​,然后单击...)
此示例使用 [TextField] 引用表数据。

Private Sub Form_Load()
  TextControl.SetFocus
  If IsNull([TextField]) Then
    TextControl.Text = ([Control1] * [Control2]) / 1000
  End If
End Sub

To accomplish this using VBA, add a Form_Load Event. (Open the form in Design View and in Form properties click the Event tab and choose Event Procedure for "On Load" and click ...)
This example uses [TextField] to refer to the table data.

Private Sub Form_Load()
  TextControl.SetFocus
  If IsNull([TextField]) Then
    TextControl.Text = ([Control1] * [Control2]) / 1000
  End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文