List Boxes

J

Joanne

Hello, I have the following subroutine, which uses the variable "j" to
increment the names of different listboxes that I set up, the first being
"ListSchools1", but the macro always stops and tells me that this list box
doesn't exist. Isn't it possible to use a list box with a variable to
identify it?

Thank you for your help.

Sub AddEducationListInfo(varBookmark As String, varRecords As Long)
Dim rng As Range
Dim i As Integer
Dim j As Integer
j = 1
Dim strListInfo As String
Dim strDegreeInfo As String
Dim strHonorsInfo As String
Set rng = ActiveDocument.Bookmarks(varBookmark).Range
For i = 0 To varRecords
If frmAttyBio.ListSchools(j).Selected(i) = True Then
strDegreeInfo = frmAttyBio.ListDegrees(j).Value
strHonorsInfo = frmAttyBio.ListHonors(j).Value
strListInfo = frmAttyBio.ListSchools(j).List(i) & " " &
frmAttyBio.ListDegrees(j).Value _
& " " & frmAttyBio.ListHonors1(j).Value


End If

Next i

rng.Text = strListInfo

End Sub
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?Sm9hbm5l?=,
I have the following subroutine, which uses the variable "j" to
increment the names of different listboxes that I set up, the first being
"ListSchools1", but the macro always stops and tells me that this list box
doesn't exist. Isn't it possible to use a list box with a variable to
identify it?
Yes, you can identify a UserForms control with a variable, but UserForm
controls don't support arrays like you're trying to do. You'd need to use
something more like:
sListBoxName = "ListSchools" & CStr(j)
If frmAttyBio.Controls(sListBoxName).Selected(i) = True then

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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