PDA

View Full Version : Grayout labels



oglezsa
04-06-2010, 10:20 AM
Hello,

Im trying to gray out the textbox labels in a userform when not selected, so far i have the textbox disable until the checkbox is selected but i want to make it easier for the user to identify what is enable or disable if or not selected...


Private Sub CheckBox9_Click()
If CheckBox9.Value = True Then
CheckBox8.Enabled = False
CheckBox8.Value = False
CheckBox7.Enabled = False
CheckBox7.Value = False
CheckBox6.Enabled = False
CheckBox6.Value = False
CheckBox5.Enabled = False
CheckBox5.Value = False
CheckBox4.Enabled = False
CheckBox4.Value = False
CheckBox3.Enabled = False
CheckBox3.Value = False
CheckBox2.Enabled = False
CheckBox2.Value = False
CheckBox1.Enabled = False
CheckBox1.Value = False

TextBox23.Enabled = False
TextBox24.Enabled = False
TextBox25.Enabled = False
TextBox26.Enabled = False
TextBox27.Enabled = False
TextBox28.Enabled = False
Else
CheckBox9.Enabled = True
CheckBox8.Enabled = True
CheckBox8.Value = False
CheckBox7.Enabled = True
CheckBox7.Value = False
CheckBox6.Enabled = True
CheckBox6.Value = False
CheckBox5.Enabled = True
CheckBox5.Value = False
CheckBox4.Enabled = True
CheckBox4.Value = False
CheckBox3.Enabled = True
CheckBox3.Value = False
CheckBox2.Enabled = True
CheckBox2.Value = False
CheckBox1.Enabled = True
CheckBox1.Value = False

End If
End Sub


Edit: VBA tags added to code

lucas
04-06-2010, 11:21 AM
How about changing their visiblitly status so they don't even show unless they are to be used?

CheckBox8.Visible = False

You can format your code for the forum by selecting it when posting and hit the vba button.

fumei
04-06-2010, 11:56 AM
I would generally recommend that you properly name your objects. In the long run, names like "TextBox28" are not helpful.

If you want to grey out the labels, then simply do that. Use a RGB value, say...
If CheckBox9.Value = True Then
CheckBox8.Enabled = False
CheckBox8.Value = False
CheckBox7.Enabled = False
CheckBox7.Value = False
CheckBox6.Enabled = False
CheckBox6.Value = False

TextBox23.Enabled = False
TextBox24.Enabled = False
TextBox25.Enabled = False
TextBox26.Enabled = False

Label346789.ForeColor = RGB(100, 100, 100)
Label19900672345177.ForeColor = RGB(100, 100, 100)
Label0.ForeColor = RGB(100, 100, 100)
Label$*%%)@#!56473411.ForeColor = RGB(100, 100, 100)

or whatever RGB colour you want. If you are starting out with RBG(0,0,0) - i.e. black - then 100,100,100 is a kind of "grayed out".

Or, yes, you could use .Visible.

oglezsa
04-06-2010, 12:29 PM
Thanks for the observations 'ill start doing it, and thanks to both of you for the solutions 'i'll be using them as well they are perfect for what i need to do.....One more thing, once the user finish generating the letter (temaplate based) and saving it with "X name" is it possible to reload a blank document based again in the same template and userform without leaving it?

fumei
04-06-2010, 12:37 PM
Yes.

oglezsa
04-06-2010, 12:41 PM
How? my template is called "1234" and is in my "Documents folder"

oglezsa
04-06-2010, 12:51 PM
i got it to the point it resets the form, but in the background where it was the document is blank and when I click generate letter it states " this command is invalid because no documnet is open

oglezsa
04-06-2010, 02:16 PM
Do i Have to open another thread for this question? if so no problem, i just dont wat to open a new one if not needed :)

lucas
04-06-2010, 02:37 PM
Use code to close the first document and add the new one. Change the name of the template to match your .dot file.

Dim oDoc As Document
ActiveDocument.Close True
Set oDoc = Documents.Add(Template:="Doc1.dot")

oglezsa
04-07-2010, 07:19 AM
It say "Form already displayed; can't show modally"

oglezsa
04-07-2010, 07:39 AM
Got it working, i just add "Unload Me"

oglezsa
04-07-2010, 08:12 AM
Thanks for the Help!!!! :thumb

fumei
04-07-2010, 09:52 AM
Let that be a lesson. Always unload your userform properly. If you are not using it...unload it.