在 VBA Access 中使用 .text 和 .value 的区别 [英] Distinction between using .text and .value in VBA Access

查看:73
本文介绍了在 VBA Access 中使用 .text 和 .value 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 textbox1.text 值传递到查询中,有时传递到字符串中:

I am passing the textbox1.text values into a query and sometimes into a string:

Dim combor1 As String
combor1 = comboReason1.Text

我怎么知道什么时候应该输入combor1 = comboReason1.Value?

How do I know when I should put combor1 = comboReason1.Value?

另外,为什么我需要为控件设置焦点以引用其属性?这对我来说没有意义.

Also, why do I need to set focus for a control to reference its property? That doesn't make sense to me.

此外,当我设置 combor4 = comboReason4.Value 并且 .value 为 null 时,我会收到关于 null 无效使用的错误.

Also, when I set combor4 = comboReason4.Value and the .value is null, then I get an error about invalid use of null.

推荐答案

  • ".text" 给你显示的内容在屏幕上
  • ".value" 为您提供底层证券价值
  • 两者通常给出相同的结果,除非相应的控件是

    Both usually give the same result, except when the corresponding control is

    1. 组合框或列表框控件
    2. 显示值与绑定列不同

    示例:

    • id_Person 是表单中的组合框控件
    • 行源是SELECT id_Person, personName FROM Tbl_Person"
    • 列宽为0cm;3cm"
    • 绑定列是 1

    在这种情况下:

    • id_Person.text 显示 Tbl_Person.personName
    • id_Person.value 显示 Tbl_Person.id_Person.

    .text 属性仅在相应控件具有焦点时可用.

    .text property is available only when the corresponding control has the focus.

    .text 是字符串值,因此不能为 Null,而 .value 可以为 Null

    .text is a string value, therefore it cannot be Null, while .value can be Null

    .text 只能在控件获得焦点时调用,而 .value 可以随时调用...

    .text can only be called when the control has the focus, while .value can be called any time ...

    这篇关于在 VBA Access 中使用 .text 和 .value 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆