grey out textbox

R

Rick Sanderson

Private Sub cef_change()
If cef = True Then
Rsph = False
End If


If the cef checkbox is selected how does one then grey out a selected
texbox, in this case Rsph, as is stands the box displays false

thanks
Rick
 
D

Debra Dalgleish

The following code will disable the textbox, and change the background
colour.

Private Sub cef_change()
If cef = True Then
Rsph.Enabled = False
Rsph.BackColor = &H8000000F
Else
Rsph.Enabled = True
Rsph.BackColor = &HFFFFFF
End If
End Sub
 
D

Dave Peterson

You can enable/disable the textbox with something like:

Option Explicit
Private Sub cef_Click()
Me.reph.Enabled = Not Me.cef.Value
End Sub

But that just disables the textbox--it doesn't make it grey. This did make it
grey on my system:

Option Explicit
Private Sub cef_Click()

If Me.cef.Value = True Then
With Me.reph
.Enabled = False
.BackColor = &H80000000
End With
Else
With Me.reph
.Enabled = True
.BackColor = &H80000005
End With
End If
End Sub

(And I used the _click procedure.)
 
R

Rick Sanderson

Thanks Debra and Dave,
next question is that the greying out and disabling is to be applied to a
bunch of textboxes, which involves the code below, which works fine, but for
future reference is it possible or beneficial to wrap this up a little
neater?
i was looking at the with command but it seems this is for applying a
variety of changes to a selection trather than a change to a variety of
selections.
TIA
Rick



Private Sub cef_change()
If cef = True Then
Rsph.Enabled = False
Rsph.BackColor = &H8000000F
Rcyl.Enabled = False
Rcyl.BackColor = &H8000000F
Raxis.Enabled = False
Raxis.BackColor = &H8000000F
Radd.Enabled = False
Radd.BackColor = &H8000000F
Rprism.Enabled = False
Rprism.BackColor = &H8000000F
Rbase.Enabled = False
Rbase.BackColor = &H8000000F
Lsph.Enabled = False
Lsph.BackColor = &H8000000F
Lcyl.Enabled = False
Lcyl.BackColor = &H8000000F
Laxis.Enabled = False
Laxis.BackColor = &H8000000F
Ladd.Enabled = False
Ladd.BackColor = &H8000000F
Lprism.Enabled = False
Lprism.BackColor = &H8000000F
Lbase.Enabled = False
Lbase.BackColor = &H8000000F

Else...................etc.etc




Debra Dalgleish wrote:
|| The following code will disable the textbox, and change the
|| background colour.
||
|| Private Sub cef_change()
|| If cef = True Then
|| Rsph.Enabled = False
|| Rsph.BackColor = &H8000000F
|| Else
|| Rsph.Enabled = True
|| Rsph.BackColor = &HFFFFFF
|| End If
|| End Sub
||
||
|| Rick Sanderson wrote:
||| Private Sub cef_change()
||| If cef = True Then
||| Rsph = False
||| End If
|||
|||
||| If the cef checkbox is selected how does one then grey out a
||| selected texbox, in this case Rsph, as is stands the box displays
||| false
||
||
|| --
|| Debra Dalgleish
|| Excel FAQ, Tips & Book List
|| http://www.contextures.com/tiptech.html
 
D

Dave Peterson

If you were doing all the textboxes, you could do something like:

Option Explicit
Private Sub cef_Change()

Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is MSForms.TextBox Then
If Me.cef.Value = True Then
With ctrl
.Enabled = False
.BackColor = &H8000000F
End With
Else
With ctrl
.Enabled = True
.BackColor = &HFFFFFF
End With
End If
End If
Next ctrl

End Sub

If they were named something nice: TB01 through TB03 (or as high as you want):

Option Explicit
Private Sub cef_change()

Dim iCtr As Long

For iCtr = 1 To 3
If Me.cef.Value = True Then
With Me.Controls("TB" & Format(iCtr, "00"))
.Enabled = False
.BackColor = &H8000000F
End With
Else
With Me.Controls("TB" & Format(iCtr, "00"))
.Enabled = True
.BackColor = &HFFFFFF
End With
End If
Next iCtr

End Sub

If there were lots, but you had the ones associated with the checkbox in a
frame, you could cycle through the controls in the frame:

Option Explicit
Private Sub cef_Change()

Dim ctrl As Control
For Each ctrl In Me.Frame1.Controls
If TypeOf ctrl Is MSForms.TextBox Then
If Me.cef.Value = True Then
With ctrl
.Enabled = False
.BackColor = &H8000000F
End With
Else
With ctrl
.Enabled = True
.BackColor = &HFFFFFF
End With
End If
End If
Next ctrl

End Sub

I'm sure that there are more ways, too!
 

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