how to find out when a ListBox is populated or select it

V

Valeria

Dear experts,
I am working on a userform.
I am inputting data from different text boxes into a
ListBox via clicking a button, and then transfering the
combined data from this ListBox into a macro via clicking
a second button.
I want the userform to tell the user that he needs to
input some data if none was entered, so I wrote this code:

If ListBox4.ListIndex = -1 Then
MsgBox "Please enter the product data before clicking on
this button"
Exit Sub
End If

The problem I have is that as at the end none of the items
in ListBox4 is selected (items are just added via clicking
the button), even if the ListBox is populated the
ListIndex returns -1.
Is there a way I can select the ListBox, or get around
this problem?

Many thanks in advance for your help!
Kind regards,
Valeria
 
B

Bob Phillips

Valeria,

Look at the Listbox ListCount property. This will return the number of items
in the listbox

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
V

Valeria

Hi Bob,
it works very well, I am really learning a lot from you,
many thanks!
Kind regards,
Valeria
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top