Distinction between using .text and .value in VBA Access

后端 未结 5 1641
悲哀的现实
悲哀的现实 2020-11-27 07:59

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

Dim combor1 As String
combor1 = comboReason1.Text
5条回答
  •  一整个雨季
    2020-11-27 08:33

    • ".text" gives you what is displayed on the screen
    • ".value" gives you the underlying value

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

    1. a combobox or listbox control
    2. the displayed value differs from the bound column

    Example:

    • id_Person is a combobox control in a form
    • the rowsource is "SELECT id_Person, personName FROM Tbl_Person"
    • column widths are "0cm;3cm"
    • bound column is 1

    In this situation:

    • id_Person.text displays Tbl_Person.personName
    • id_Person.value displays Tbl_Person.id_Person.

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

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

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

提交回复
热议问题