Passing a Forms Control to Function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to write a function that checks a listbox for an entry and reports
true or false. I want the input to be the listbox to check and the potential
entry. How do I pass the listbox to the function?

Thanks,
Pflugs
 
as an example


Function myFunc(lb As MSForms.ListBox)
MsgBox lb.Value
End Function


and in the form

myFunc Me.ListBox1


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Function myFunction(myLB as msforms.listbox) as boolean

End Function

I'm not sure what you mean by potential entry, though.
 
Thank you, that worked well.

I have one more question, if you please. I am trying to return the value of
a list item at index "i"; that is, looping through the list and reporting the
string of the selected items. After reporting them, I'd like to remove them
from the list, but each time I remove one, it changes the indexes. Is there
a better way to get around this?

Thanks,
Pflugs
 
loop in reverse

With listbox1
for i = .listcount - 1 to 0 step -1
if .selected(i) then
.removeitem i
end if
next
End with
 
Good call. Thanks.
Pflugs

Tom Ogilvy said:
loop in reverse

With listbox1
for i = .listcount - 1 to 0 step -1
if .selected(i) then
.removeitem i
end if
next
End with
 

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

Back
Top