Looping Problem

R

Robbyn

Greetings all. I think I've been looking at this project too long because I can't figure out why the following code
doesn't work (Being a VBA beginner doesn't help either). The code doesn't do what it's supposed to. If cmb27-3
is not "NA" then cmb32-41 add "lesson" & k. If is "N/A" then disable cmb32-41. But cmb32-41 are disabled every time
What am I not seeing? :( BTW, cmb=combobox

Private Sub cmb27_Change(
Dim i As Intege
Dim j As Intege
Dim k As Intege

For i = 27 To 3
For j = 32 To 4
For k = 1 To 2
If Me.Controls("cmb" & i).Text <> "N/A" The
Me.Controls("cmb" & j).AddItem "Lesson" & " " &
Else: Me.Controls("cmb" & j).Enabled = Fals
End I
Next
Next
Next

End Sub
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Try this:

For i = 27 To 31
If Me.Controls("cmb" & i).Text <> "N/A" Then
For j = 32 To 41
For k = 1 To 26
Me.Controls("cmb" & j).AddItem "Lesson" & " " & k
Next k
Next j
Else
For j = 32 To 41
Me.Controls("cmb" & j).Enabled = False
Next j
End If
Next i


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
R

Robbyn

Hi Doug. Thanks for your reply. Your code didn't work either :( I got the following to work (I just adde
Me.Controls("cmb" & j).Enabled = True to the code you provided)

For i = 27 To 3
If Me.Controls("cmb" & i).Value = "N/A" The
For j = 32 To 4
Me.Controls("cmb" & j).Enabled = Fals
Next
ElseIf Me.Controls("cmb" & i).Value <> "N/A" The
For j = 32 To 4
For k = 1 To 2
Me.Controls("cmb" & j).Enabled = Tru
Me.Controls("cmb" & j).AddItem "Lesson" & " " &
Next
Next
End I
Next

Have a nice day.
Robbyn
 

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