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 derfloh 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

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
can soemone help me with this.
 
Try testing for a value by using "" instead of using Null.

Using your code...

If me!cboItem.Value = "" Then
MsgBox "Please Select an item first"
Exit Sub
End If
 
Using "" can lead to a problem with a null value.

If me!cboItem = "" or isnull(me!cboItem) then
msgbox "Please Select an Item First"
Exit sub
end if.

However this can be shortened and is garanteed to work in 99% of cases.
If Trim(" " & cboitem) = "" then
msgbox "Please Select an Item First"
Exit sub
end if.
 
Better usability, is to leave the button disabled until the user selects a value from the list. In design view, make the enabled property of the button, "False". On the AfterUpdate event of the combo box, put this line of code:


Me.ButtonName.Enabled = Not IsNull(Me.ComboBoxName) Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top