Solved Looping on a form for several textboxes to be enabled

donkey9972

Registered User.
Local time
Today, 12:57
Joined
May 18, 2008
Messages
121
Ok I have a form where I need to run a loop. The problem is I can get the first set of textboxes to enable on the loop, I just do not know how to get the 2nd set of boxes to be enabled.

So here is the code I am trying to play around with but I am not sure if it has to be a 2nd if loop or if it goes under the else or what.
Code:
Dim i As Integer

If Me.NumTrucks > 0 Then
    For i = 1 To 17
        Me("A" & i).Enabled = True
    Next
Else
End If
If Me.NumTrucks > 1 Then
    For i = 1 To 17
        Me("A" & i).Enabled = True
        Me("B" & i).Enabled = True
    Next
Else

End If

The first part works good, just the 2nd part isn't.
 
Okay I finally got this working sort of using this code
Code:
Dim i As Integer

If Me.NumTrucks = 0 Then GoTo Zero
If Me.NumTrucks = 1 Then GoTo One
If Me.NumTrucks = 2 Then GoTo Two
    
Zero:
    For i = 1 To 17
        Me("A" & i).Enabled = True
    Next
GoTo Done

One:
    For i = 1 To 17
        Me("A" & i).Enabled = True
        Me("B" & i).Enabled = True
    Next
GoTo Done

I had to put it in the after update for my control text box. The problem I am having now, is lets say a mistake is made, they enter a 1 by mistake instead of a 0, then it enables the text boxes that correspond to the 1. If they go back to correct the mistake back to 0, it does not seem to disable the boxes in the B section like I though it would. Any guidance on how to get it to do that?
 
Nevermind, I just figured it out. I simply have to add a line of code that turns enabled false.
 
You have a serious design problem. You have a repeating group which violates first normal form. Whatever the data is in this group of fields, it doesn't belong in the table where you have the repeating group. It belongs in a separate table and you would use a subform to work with the data, ONE ROW for each field.

Please spend some time reviewing database normalization principles. You may find this hard to believe but doing it right will save you an awful lot of work.
 
You should use a select case statement.

Rich (BB code):
select case Me.NumTrucks

case 0

case 1

Case 2

case else

end select
 
Is there a 3rd group?
Don't need Case nor branching. Don't need separate line to set Enabled False. Consider:
Code:
For i = 1 To 17
     Me("A" & i).Enabled = Me.NumTrucks >= 0
     Me("B" & i).Enabled = Me.NumTrucks >= 1
     Me("C" & i).Enabled = Me.NumTrucks >= 2
Next
 

Users who are viewing this thread

Back
Top Bottom