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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stuck for combobox code 1

Status
Not open for further replies.

thelocaluk

Technical User
Dec 8, 2005
11
GB
I'm a bit lost for what I put in place of the ? in this code. I want to check if combobox1 selection has been made but combobox2 has no selection then to bring up message.

Code:
If Me.cmbReason.Value = ? And Me.cmbDes.Value = "" Then
  Me.cmbDes.SetFocus
  MsgBox "Please enter Description"
  Exit Sub
 End If
 
Perhaps something like:
Code:
If Me.cmbReason.ListIndex <> -1 Then
  If Me.cmbDes.ListIndex = -1 Then
    Me.cmbDes.SetFocus
    MsgBox "Please enter Description"
    Exit Sub
  End If
End If


Regards,
Mike
 
First of all, are you looking for a specific selection criteria for the combobox, or just any one? Also, do you have a "null" item? - that is, quite often people put an explanatory item at the top of the list. Something like "Please select an item".

Gerry
 
Thanks Mike, this is what I did
Code:
If Me.cmbReason.ListIndex <> -1 Then
  If Me.cmbDes.ListIndex = -1 Then
    Me.cmbDes.SetFocus
    MsgBox "Please enter Description"
    Exit Sub
  End If
End If

Fumei, how do I go about adding an explanatory item to the top of a list?
 
It is simply one of the items, usually the first one.

If you AddItem to a combobox and do nothing more then the initial item displayed is Null...no item is shown. But if you have:
Code:
Combobox1.AddItem "Please select blah blah"
Combobox1.AddItem "First real item"
Combobox1.AddItem "Second real item"
Combobox1.AddItem "Third real item"
Combobox1.ListIndex = 0
then the combobox will initially display with ListIndex 0 (Please select blah blah).

Just remember if you are using ListIndex to get the values that 0 is your explanatory item!


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top