I am passing the textbox1.text
values into a query and sometimes into a string:
Dim combor1 As String
combor1 = comboReason1.Text
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.
Also, when I set combor4 = comboReason4.Value
and the .value
is null, then I get an error about invalid use of null.
Not all VBA methods can be used with all types of references. For example, the “Value” method tells Excel to store a value in a relevant cell, or an array of values in a relevant range. If you stored a range of values in a variable, you cannot use the value method to attach that array to a single cell.
The Text property may be different than the Value property for a text box control. The Text property is the current contents of the control. The Value property is the saved value of the text box control. The Text property is always current while the control has the focus.
Text is a string. It represents the actual text the user sees on the screen. Value is an object and can be any value. The reason they are different is because you can use the Combo as a sort've lookup table.
The only difference between this property and the Value property is that the Value2 property doesn't use the Currency and Date data types. You can return values formatted with these data types as floating-point numbers by using the Double data type.
Both usually give the same result, except when the corresponding control is
Example:
In this situation:
.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 ...
You can use the Text
property to set or return the text contained in a text box or in the text box portion of a combo box.
To set or return a control's Text
property, the control must have the focus, or an error occurs. To move the focus to a control, you can use the SetFocus method or GoToControl action.
You can use the Value
property to determine or specify if a control is selected, the selected value or option within the control, the text contained in a text box control, or the value of a custom property.
The Value
property returns or sets a control's default property, which is the property that is assumed when you don't explicitly specify a property name. In the following example, because the default value of the text box is the value of the Text property, you can refer to its Text property setting without explicitly specifying the name of the property.
Forms!frmCustomers!txtLastName = "Smith"
Text Property Reference
http://msdn.microsoft.com/en-us/library/aa173453.aspx
Value Property Reference
http://msdn.microsoft.com/en-us/library/aa173476.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With