List box problem
Hi all,
I have created a user form named userform3, and in that userform there is 5 list-box. There are two button for 'ok' and 'cancel' as well in that userform. corresponding to 'ok' button following codes are there:
Private Sub OKButton1_Click()
Dim check As Integer
If UserForm3.ListBox1.ListIndex = -1 Or UserForm3.ListBox2.ListIndex = -1 Or UserForm3.ListBox3.ListIndex = -1 Or UserForm3.ListBox4.ListIndex = -1 Or UserForm3.ListBox5.ListIndex = -1 Then
check = -1
Else
check = 1
End If
If check > -1 Then
Unload Me
MsgBox UserForm3.ListBox1.ListIndex
Else
MsgBox "No option is selected.", , "Error Message"
End If
End Sub
My problem is that when 'check' is 1 then the message box should give the value 0 or 1 (assuming that there is only two items in any of list box), but message box is still giving the value as -1 showing that no item is selected.
However if I put same code i.e. - MsgBox "No option is selected.", , "Error Message", just after first 'if' loop and before second 'if' loop then it gives correct result. That is somehow the value of listbox1 item is lost.
Can anyone tell me what is the remedy?
And my second question is that, is there any way to put a particular item as selected by default?
If anyone here can throw some light on my problems I will be very grateful.
Thanks and regards,
Arun
|