Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMBO BOX ( NULL VALUE) 1

Status
Not open for further replies.

alifyag

MIS
Apr 15, 2002
18
US
hello,
i have a combo box with a list of drop down values in it. also i have a add button. if the user chooses something from the combo box and clicks on add then it gets added to another list box.
however my problem is that when the form opens the first time and the user directly clicks on the add without choosing soemthign from the combo box then a message should be displyed saying "to choose item first".
i tried the follow code but without luck
If me!cboItem.Value = Null Then
MsgBox "Please Select an item first"
Exit Sub
End If
i also tried
If me!cboItem.Value = "" Then
MsgBox "Please Select an item first"
Exit Sub
End If

can soemone help me with this.
 
The first attempt (me!cboItem.Value = Null) fails because it will always be False. The reason is that comparing anything to Null always results in Null, which is treated like False in an If expression. Even "If Null = Null" comes out False!

The second attempt (me!cboItem.Value = "") fails because the value is Null, which is not the same thing as an empty string.

The correct way to test for Null is with the IsNull() function:
If IsNull(me!cboItem.Value) Then ... Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top