'Change the color of all output in form according to item selected

Harry92

Registered User.
Local time
Today, 13:45
Joined
Apr 29, 2008
Messages
19
Ok, I have a form with the following combo box (blank, 1, and 2).

Selecting “blank” from the drop down, all the text within that record would be black (default).

Selecting “1” from the drop down, all the text within that record would be blue.

Selecting “2” from the drop down, all the text within that record would be orange.

Is it possible to store the color change of the record to the table and report? Printing the report, will it display the colors?

Below is my code that tried to follow from an example in my book. Thanks in advance.

Private Sub ComboBox1_Change()
'Change the color of all output in form according to item selected
Select Case TextBox1
Case " "
TextBox1.ForeColor = vbBlack
Case "1"
TextBox1.ForeColor = vbBlue
Case "2"
TextBox1.ForeColor = vbOrange
End Select
End Sub
 
You really should put the code in the AfterUpdate event, and the Select Case needs to be for the combobox, something like this:

Code:
Private Sub ComboBox1_AfterUpdate()
'Change the color of all output in form according to item selected
  Select Case ComboBox1

  Case "1"
   TextBox1.ForeColor = vbBlue
  Case "2"
   TextBox1.ForeColor = vbOrange
  Case Else
   TextBox1.ForeColor = vbBlack
End Select
End Sub

For the colors to persist, as you move from record to record, you'll have to have the same code in the form's On Current event, as well.

This will only work if you're using a Single view form. For datasheet or continuous view forms you'd have to use Conditional Formatting to do the job, and in point of fact, that's what I'd do in any case, assuming you're using v2000 or higher. Especially if you have a number of fields to worry about. You can also use Conditional Formatting, I believe , to set the colors in a report.

IF you'd like to go that route I can help you later. I've got to step out, but I'll check back in about 2 hours.

Linq
 
Last edited:
You really should put the code in the AfterUpdate event, and the Select Case needs to be for the combobox, something like this:

Code:
Private Sub ComboBox1_AfterUpdate()
'Change the color of all output in form according to item selected
  Select Case ComboBox1

  Case "1"
   TextBox1.ForeColor = vbBlue
  Case "2"
   TextBox1.ForeColor = vbOrange
  Case Else
   TextBox1.ForeColor = vbBlack
End Select
End Sub

For the colors to persist, as you move from record to record, you'll have to have the same code in the form's On Current event, as well.

This will only work if you're using a Single view form. For datasheet or continuous view forms you'd have to use Conditional Formatting to do the job, and in point of fact, that's what I'd do in any case, assuming you're using v2000 or higher. Especially if you have a number of fields to worry about. You can also use Conditional Formatting, I believe , to set the colors in a report.

IF you'd like to go that route I can help you later. I've got to step out, but I'll check back in about 2 hours.

Linq

Thanks Linq.

I did the follow as you suggested in the single vie form and it works great with the color text.

I’m having a problem seeing the color text in the report and when printing.

Case and If…Else statement are almost the same? If so, when to use either one?

Is there an efficient way of reducing the code below with 20 text box?

Private Sub ComboBox1_AfterUpdate()
'Select 0 or 1 from ComboBox1
'If "0" is selected, Output TextBox20 are Null and grayed out Stop

If Me.ComboBox1 = "1" Then
Me.TextBox20 = " "
Me.TextBox20.Enabled = False
Else
Me.TextBox20.Enabled = True
End If

'Change the color of all output in form according to item selected
Select Case Active
Case "0"
TextBox1.ForeColor = vbRed
.
.
.
TextBox20.ForeColro = vbRed
Case Else
TextBox1.ForeColor = vbBlack
.
.
.
TextBox20.ForeColro = vbBlack
End Select
End Sub
 
I tried this in my own form, and it works for the parent form, but not any of the sub forms. Any suggestions?
 
Luddite_Lad,

I have a Form named fmr_WorkOrders containing a sub-Form named fmrInvoiceDetails. I want to place a Combo on the WorkOrders Form that will select the Program Run Mode (Production, QA, and Development). Each Mode will have a different colored background. I have the whole thing working except for the sub forms.

According to the instruction in the link you sent, to refer to a control property in a Sub Form, I would use the following syntax:

Me!Subform1.Form!ControlName.<Property>=<Setting>

I interpret this as the following:

Me!fmrInvoiceDetails.Form!FormHeader.BackColor = 8421631

When I use this format, Access returns the following error message:

“Microsoft Office Access can’t find the field ‘fmrInvoice_Details’ referred to in your expression

Any thoughts as to where I am going wrong?
 
I finally found the answer in a post by a regular in here a while back.

You're close, but not quite there:
Use:
Code:
[Forms]![GID/PO Maintenance].[Display GID/PO].Form.[btnAssign].Visible = False

Anyway, the Sub-Form Backgrouind characteristics are updated, and We are ready to proceed to the testing stage.

I would like to again thank Luddite_Lad for his assistance, and to give appropriate credit to boblarson for the final solution.
 
Sorry, Harry! I have some mobility problems that keep me off-line unexpectedly sometimes. As I said before, I think, if you're going to be doing this for a large number of textboxes, and from what you now say it sounds like 20 (is that correct?) and you want to duplicate this formatting in a report, you're probably better off using Conditional Formatting, assuming you're running Access 2000 or later. You can select all 20 textboxes, goto Conditional Formatting and do what you need to all 20 controls at one time.

As to your new question, are you talking about a setting the enable/disable property with the same combobox as before, or is this a separate combobox? If this is a separate combobox, go on and give me the actual name of each one, to simplify things.

Also understand, that selecting "0" is not the same as making no selection from a combobox, which means that its value is NULL.

After you get back to me on this question I'll get back to you with the step by step for using Conditional Formatting.

Linq
 
Last edited:
Sorry, Harry! I have some mobility problems that keep me off-line unexpectedly sometimes. As I said before, I think, if you're going to be doing this for a large number of textboxes, and from what you now say it sounds like 20 (is that correct?) and you want to duplicate this formatting in a report, you're probably better off using Conditional Formatting, assuming you're running Access 2000 or later. You can select all 20 textboxes, goto Conditional Formatting and do what you need to all 20 controls at one time.

As to your new question, are you talking about a setting the enable/disable property with the same combobox as before, or is this a separate combobox? If this is a separate combobox, go on and give me the actual name of each one, to simplify things.

Also understand, that selecting "0" is not the same as making no selection from a combobox, which means that its value is NULL.

After you get back to me on this question I'll get back to you with the step by step for using Conditional Formatting.

Linq

I have many tables that I stored data to use as a look up in the main table to reduce redundancy.

The first table (Active), data enter in the records (Active) has “0” = non-active and “1” = active. The second table (Type), data enter in the records (ModelType) has 500, 510, and 520.

I created a main table (ABC) where I linked those two tables (Active and Type) and many other tables as lookup (Combo Box). I also have 20 text box (Description, Comment, etc) for inputs.

Now I created a form (frmABC) from main table (ABC), within frmABC; when I select “0” from the combo box. I wanted all the texts (all combo box and text box) to be red. Selecting “1” from the combo box will produce all the text to be black. The input data are store in the table (ABC)

I’m able to achieve the color change within the frmABC.

When I view table (ABC), all the text are black; I do not see any red text when a “0” was selected. I want to be able to print the tables or report with the color change. I think this is possible and I do not know how to go about this. I hope this made sense or maybe I’ve confused the heck out of you? Thanks
 
I'm sorry, Harry. I've tried to help you with this, but each time you post you change your explanation of what you're trying to do and of what criteria you're using. Perhaps someone else will be able to understand your needs better than I can.

As to your comment about all the text in the table being black, that's correct, of course. Formatting text color in a form or report has nothing to do its appearance in the table display. A Table is a table; there's no formatting to be done there. That's why tables should never be seen by users, much less interacted with!

Good ;uck!
 
I'm sorry, Harry. I've tried to help you with this, but each time you post you change your explanation of what you're trying to do and of what criteria you're using. Perhaps someone else will be able to understand your needs better than I can.

As to your comment about all the text in the table being black, that's correct, of course. Formatting text color in a form or report has nothing to do its appearance in the table display. A Table is a table; there's no formatting to be done there. That's why tables should never be seen by users, much less interacted with!

Good ;uck!

That's fine. Thanks for your help
 

Users who are viewing this thread

Back
Top Bottom