enabling/disabling text boxes

VBAmalta89

Board Regular
Joined
Mar 25, 2011
Messages
116
I have a 8 frames in a user form which are activated by means of a user inputting a number in a text box, so for example, if the user enters 7 then 7 frames out of 8 are enabled.

My problem is that, within each frame i have a series of disabled text boxes which i need to remain disabled even when the fraame becomes enabled. For some reason these text boxes become enabled once the frame is enabled.

Any idea how to work round this please?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Disable the text boxes using the same code you employ to enable the frame? After the frame is enabled.
 
Upvote 0
i was thinking of that but i dont know how to do it. The code i use to enable teh frames is shown below. How can i add onto it to disable the text boxes now?

Code:
Private Sub ZoneNum_Change()

    OnlyNumbers
    
    Dim i As Long
    Dim Ctrl As Control
    
        If (Val(ZoneNum.Value)) > 8 Then
    
    MsgBox "Sorry, maximum of 8 zones allowed for Calculator"
    
   Else
   
    For i = 1 To Val(ZoneNum.Text)
        For Each Ctrl In Me.Controls("Frame" & i).Controls
            Ctrl.Enabled = True
        Next Ctrl
    Next i
    For i = Val(ZoneNum.Text) + 1 To 8
        For Each Ctrl In Me.Controls("Frame" & i).Controls
            Ctrl.Enabled = False
        Next Ctrl
    Next i
    
    End If
    
End Sub
 
Upvote 0
You're specifically enabling all the controls in each frame. You're not enabling/disabling the frames with that code.

All you need is something like this:

Code:
Me.Frame1.Enabled = True
Me.Frame1.Controls("TextBox1").Enabled = False
 
Upvote 0
Read your post below. If I understand you correctly:


Code:
Private Sub ZoneNum_Change2()
    OnlyNumbers
 
    Dim i As Long
    Dim Ctrl As Control
 
    If (Val(ZoneNum.Value)) > 8 Then: MsgBox "Sorry, maximum of 8 zones allowed for Calculator": Exit Sub
 
    Me.Controls.Enabled = False
 
    For i = 1 To Val(ZoneNum.Text)
 
        For Each Ctrl In Me.Controls("Frame" & i)
 
            Ctrl.Enabled = True
 
        Next Ctrl
 
    Next i
 
    For i = Val(ZoneNum.Text) + 1 To 8
 
        Me.Controls("Frame" & i).Enabled = False
 
    Next i
  
End Sub
 
Last edited:
Upvote 0
what happens is this:

There are 8 frames in teh form. The user will input a number from 1-8 in a text box and, consequently, that number of frames are enabled. So if the user enters 3 in the text box, the first 3 of the 8 frames are enabled. However, i would like the text boxes in the frame to remain disabled even when the frame is enabled by the user.
 
Upvote 0
I left something in there that shouldn't be there, and screwed up some other parts. Try it out.

Code:
Private Sub ZoneNum_Change2()
 
    OnlyNumbers
 
    Dim i As Long
    Dim Ctrl As Control
 
 
If (Val(ZoneNum.Value)) > 8 Then: _
    MsgBox "Sorry, maximum of 8 zones allowed for Calculator": _
    Exit Sub
 
 
For Each Ctrl In Me.Controls
 
    Ctrl.Enabled = True
 
Next Ctrl
 
 
For i = Val(ZoneNum.Text) + 1 To 8
 
    Me.Controls("Frame" & i).Enabled = False
 
Next i
 
End Sub


Edit. More stupidity tweaks.
 
Last edited:
Upvote 0
nope sorry its not working well.
the frames are remaining all enabled rather than how they were before wen only the requried number are enabled. PLus the text boxes are still enabled!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top