Solved Disable group of text boxes based on value of another text box (1 Viewer)

donkey9972

Registered User.
Local time
Yesterday, 21:14
Joined
May 18, 2008
Messages
193
Hi, I have been scouring the internet and I can't find a solution to my issue. I have 10 text boxes on a form. The main one (TB1) will be a number between 1 to 9 and also null. What I am trying to do is have the other 9 boxes disabled if TB1 is null, and if there is lets say a 5 in TB1 then only the first 5 boxes are enabled the other 4 are disabled. I am trying to avoid using numerous lines of code like this:
Code:
If Me.TB1.Value = 1 Then
Me.BT2.Enable = False
Me.BT3.Enable = False
Me.BT4.Enable = False
Me.BT5.Enable = False
Me.BT6.Enable = False
Me.BT7.Enable = False
Me.BT8.Enable = False
Me.BT9.Enabled = False
Me.BT10.Enabled = False

And then another set of code like that if there is a 2 entered, then 3, etc.... there has to be a better way, I just have no idea how to accomplish it. But if there isn't, then I guess I would have no choice but to do it that way, but I am hoping there is a better way.
 
Perhaps you can use a loop then?
 
Were I you, I'd set all of them to FALSE to begin with.
Then you have one line for each value you are testing, something like
IF Me.TB1 > 0 THEN Me.Btn1.Enable = True
IF Me.TB1 > 1 THEN Me.Btn2.Enable = True
ect...
 
Thank you for all of the replies. I think I have found my answer within everything given to me. Much appreciated.
 
Ok, let me take this a step further and ask if there is a way to implement this code
Code:
Dim i As Integer
If Me.BT1 > 0 Then
    For i = 1 To 9
         Me("A" & i).Enabled = True
    Next
End If
onto a subform?
Of course you can, just replace Me with the correct subform reference.
 
I will give it a shot, I just took my post and started a new thread on it, I wasn't sure if I was allowed to continue the thread in a different direction like that or not.
 
I will give it a shot, I just took my post and started a new thread on it, I wasn't sure if I was allowed to continue the thread in a different direction like that or not.
No worries. Good luck!
 
OK, I might need a little more help on this part with the sub-form. Here is the setup for my main/sub-form. I have 7 buttons on the main form. With the click of each button a different form appears in the unbound sub-form. Is the code supposed to be on the sub-form or is it supposed to be on the main form?

Code:
Dim i As Integer

If Me.NavigationSubform.DT1 > 0 Then
For i = 1 To 17
 Me("A" & i).Enabled = True
Next
End If
 
And then another set of code like that if there is a 2 entered, then 3, etc.... there has to be a better way,
There is. Your problem is almost certainly a poor schema design. Anytime you have numeric suffixes for fields/controls, you have a repeating group and the "columns" should actually be implemented as "rows" in a second table. Then you use a subform to show the list of items.
 

Users who are viewing this thread

Back
Top Bottom