开发者

Access 2007 vba null

开发者 https://www.devze.com 2023-04-05 10:02 出处:网络
My program doesn\'t process past this statement: Dim valid as Boolean If MyComboBox.Value Is Not Null Then valid = true

My program doesn't process past this statement:

Dim valid as Boolean
If MyComboBox.Value Is Not Null Then valid = true

Why not?

If I try to step through using stop points the program does not proceed to the next step, but the fo开发者_运维问答rm keeps running as if no vba code is being run. This is annoying because it means the form can still be used as if nothing is wrong but the intended behavior is not occuring.


The IS keyword is used for testing the state of objects and you want to test a value. The following works fine:

Dim Valid as Boolean

If Not IsNull(MyComboBox.Value) Then Valid = True

See the following link for a more detailed description:

Nothing? Empty? Missing? Null?


Use this function this way (at least in Excel) raises an error, because Null AFAIK can only be used to test objects (and the value property is not an object).

Therefore... if you want to set valid = TRUE when there is at least one selected value in the Combobox, I believe I'd use

valid = CBool(Len(MyCombobox.Value))

Hope it helps... and hope I haven't misunderstand your question :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消