Solved Determine the value stored in a ComboBox

Romio_1968

Member
Local time
Today, 23:10
Joined
Jan 11, 2023
Messages
126
I have a Combo with the source on a query.
On loading the Form, the Combo value is set to

Me.DomainCombo_1 = ""

In my understanding, this will load a string instance of zero length as Combo value.
No change or other interaction with the control before saving, so up to the end it keeps sa initial loaded value

On save, I want to check if any value was loaded in the Combo

Using an If statment, by checking
For the test> If IsNull(Me.Combo) Or Len(Me.Combo) = 0, the answer is TRUE
For the test> If ((Nz([Media_Box], 0) = 0) , the answer is FALSE

Can anybody explain me the difference?
Thank You
 
Last edited:
A zls is not a null, strings cannot be null, only numbers and number types such as date or yes/no.

if your combo is bound to a field it’s type will be the same as the field, otherwise it will be dictated by the bound column of the rowsource

a common method to cover both is to use the nz function

if nz(somevalue, ‘’)=‘’ then
 
NULL and "" are very different things. NULL is the unknown, undefined, "" on the other hand is already a string (without content).

strings cannot be null
This statement is incorrect. In a database table (SQL world), each field of each data type can also have NULL content. In the VBA world, only the Variant data type can accept NULL for values.
 
Last edited:
If I read that right, your combo box is bound to a query. From the rest of what you say, the combo must be set with .LimitToList = FALSE because otherwise, the value of the combo is more difficult to determine.

If the .LimitToList setting is TRUE then I'm not sure what the value will be once focus moves away from the combo box if it has not been selected. It would depend on the default value for the bound column, and the .Text property would no longer be available. (I.e. the .Text property is a focus-only property.) There are multiple conditions for which .LimitToList would automatically be set to TRUE, so the odds are that you are are working with a limited combo, and that has side-effects.

The correct way to determine if anyone has selected something from a limited combo box is to test its property .ListIndex, which will be -1 if the combo has no selection. For a non-limited combo, you run the risk of modifying data in the underlying form's field that is the .ControlSource for that combo. An inadvertent SAVE operation would update the form's underlying record even if someone had just "diddled" with the combo box.
 
The combo box will return the datatype of the bound column, which may be a number or a string.

To clear it, the easiest way is me.mycombo = null

You can initialise it depending on the data type with
me.mycombo = "12" or
me.mycombo = 1

but one of these may give you a type mismatch. You should know the data type of the combo box.
 

Users who are viewing this thread

Back
Top Bottom