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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically selecting fields in VBA 1

Status
Not open for further replies.

tdfreeman

MIS
Mar 28, 2002
85
US
I have an interesting situation. I have created a crosstab query and have created a report off of it. I want to do some conditional formatting on the report, but I need to be able to dynamically assign the field name that I am formatting.

For example, I have columns that represent days of the month. If the day of the month is a weekend, I want it to have a different color background.

I know how to determine if the day of the month is the weekend, however, when I find out which days of the month are on the weekend I want to be able to find that field/control and change the background color.

For example:

Let's say I have determined that the 4th of October is a weekend. My column/field in the crosstab query is 4. I need to assign 4 to the field's name so that I can reference it and change the background color.

I had thought I could create a field variable and assign the name property, but the field variable is read-only and I can't. What I was trying (to maybe help with understanding what I am asking) was:

Dim fldName as Field

fldName.Name = "4"
Me!fldName.Backcolor = RGB(255, 211, 155)

As I said before, this results in a read-only error.

Any ideas?

Thanks in advance for your help.

Tammy

Thank you for your help.

Tammy
 
tdfreeman:

I'm not sure if i understood what you want to do, also i don't see the need to create fld variable, since all what you display (in the form) are -txt,lst,cbo- boxes, you are not going to modify their values, just their properties.
So if you want to "Get" the name of the control to be formated you can do something like this:

dim ctl as control
dim lngcolor as long
lngColor = 10212095 'peach

Set ctl = Me.Controls(strCtlName)
ctl.Backcolor = lngColor

it think it should solve your problem

good luck

Estuardo
 
Thank you Estuardo.

I had already figured out that it was a control I needed and not a field. So, I had figured it out. (I tend to write a question and then figure it out later. But I can never figure it out before I write the post).

Thanks,

Tammy

Thank you for your help.

Tammy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top