Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Back color of Option Group box through code?

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
I am trying to change the color of controls on a form through code by looping through a list of controls in a table.

The line of code I use is
me.controls(strControlname).backcolor = vbred

However it changes the color for everything except the option group box. I do not understand this as I can change its color manually through the properties and it works.

I do not get an error but I know it loops through it as I tested it with message boxes!

Any help appreciated?

Cheers

Neemi
 
Hi neemi,

I don't have any trouble doing it. Can you post some more of your code and anything else relevant.

Enjoy,
Tony
 
Try
me.CONTROLNAME.backcolour = vbred

rather than

me.controls(strControlname).backcolor = vbred

I am not sure if it will like the name being converted to a string
 
Hi Sylv4n.

I need to loop through a table that contains the control names as when a user selects a value from a dropdown list the controls that change color differ.

Also i have tryed to make it more versitile and store the information in a table.

The code that I am using is as follows:-

'// =====================================================================================
'// Quality Checking - Setting the backcolors of required fields to red
'// =====================================================================================
Dim strSQL As String
Dim strSQLReset As String
Dim intTag As String
Dim strField As String
Dim strFieldReset As String

'// SQL strings
strSQL = "SELECT TAG, FIELD_NAME, " & g_strOutcomeCode & " FROM tlkpQualityCheck_Vertex WHERE " & g_strOutcomeCode & " = TRUE"

'// Set the backcolor of required fields to red
Dim rs As New ADODB.Recordset
rs.Open strSQL, CurrentProject.Connection, adOpenKeySet, adLockOptimistic

If rs.RecordCount > 0 Then

rs.MoveFirst
Do Until rs.EOF

strField = rs![FIELD_NAME]
intTag = rs![Tag]

Me.Controls(strField).BackColor = vbRed
rs.MoveNext

Loop

rs.Close

End If

'// =====================================================================================


strField is the parameter that stores the control name.

The code works fine and loops through the correct controls changing the relevent control backcolors... It even loops through the Option Box, (as I have discovered from message boxes), but it doesn't appear to change the color!!

I can't see why as when i do it through the properties of the form it changes color!

Any Ideas!

Cheers

Neemi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top