Wrox Programmer Forums
|
BOOK: Excel 2000/2002 VBA Programmer's Reference
This is the forum to discuss the Wrox book Excel 2000 VBA: Programmers Reference by John Green, Stephen Bullen, Felipe Martins, Brian Johnson; ISBN: 9780764544019
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Excel 2000/2002 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 29th, 2007, 04:30 AM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
List Box Problem aliirfan84 ASP.NET 2.0 Professional 0 May 24th, 2007 06:40 AM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
List Box Text problem balesh ASP.NET 1.0 and 1.1 Professional 1 August 31st, 2006 07:05 AM
List Box Problem informaniac ASP.NET 2.0 Basics 2 August 30th, 2006 05:37 AM
multiselect list box display selected problem pmcquirk Javascript How-To 12 January 18th, 2005 12:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.