Using Variables to for Controls

G

Guest

I am trying to use a variable to represent text boxes on a form so that I can
cgahne the background colors of different boxes.

For I = 1 To 2

strWGT = "AVG_WT_" & LTrim(Str(I))

If [Forms]![Mil Spec Data Entry](strWGT) >= [WEIGHT SPEC] Then
[Forms]![Mil Spec Data Entry](strWGT).BackColor = 4259584
[Forms]![Mil Spec Data Entry](srtWGT).ForeColor = -2147483640
Else
[Forms]![Mil Spec Data Entry](strWGT).BackColor = 255
[Forms]![Mil Spec Data Entry](strWGT).ForeColor = 16777215
FailStatus = "FAIL"

End If

I keep getting 'Object doesn't support this property or method' error.

How can I get this to work??
 
G

Guest

Thanks for trying Paul.

I tried your suggestion and got the same error.

Paul Overway said:
Forms("Mil Spec Data Entry").Controls(strWGT).BackColor = 4259584
Etc..

--
Paul Overway
Logico Solutions
http://www.logico-solutions.com


DWNH said:
I am trying to use a variable to represent text boxes on a form so that I
can
cgahne the background colors of different boxes.

For I = 1 To 2

strWGT = "AVG_WT_" & LTrim(Str(I))

If [Forms]![Mil Spec Data Entry](strWGT) >= [WEIGHT SPEC] Then
[Forms]![Mil Spec Data Entry](strWGT).BackColor = 4259584
[Forms]![Mil Spec Data Entry](srtWGT).ForeColor = -2147483640
Else
[Forms]![Mil Spec Data Entry](strWGT).BackColor = 255
[Forms]![Mil Spec Data Entry](strWGT).ForeColor = 16777215
FailStatus = "FAIL"

End If

I keep getting 'Object doesn't support this property or method' error.

How can I get this to work??
 
R

Rick Brandt

DWNH said:
Thanks for trying Paul.

I tried your suggestion and got the same error.

What kind of a control is it? Perhaps it doesn't have a BackColor property
(not all controls do).
 
F

Fred Wilson

The listed below is aircode but it should work.

dim frmMilSpec as Form
dim ctrWT as control
dim strWGT as string

Set frmMilSpec = Forms("Mil Spec Data Entry")

For I = 1 to 2

strWGT ="AVG_WT_" & LTrim(Str(I))

set ctrWT = frmMilSpec.Controls(strWGT)

If ctrWT >= [WEIGHT SPEC] Then
with ctrWT
.BackColor=
.ForeColor=
End with
Else
with ctrWT
.BackColor=
.ForeColor=
End with
failStatus = "FAIL"
End If
 
G

Guest

I figured out my problem, I was using the wrong name for a control.

Thanks for all the replies

Fred Wilson said:
The listed below is aircode but it should work.

dim frmMilSpec as Form
dim ctrWT as control
dim strWGT as string

Set frmMilSpec = Forms("Mil Spec Data Entry")

For I = 1 to 2

strWGT ="AVG_WT_" & LTrim(Str(I))

set ctrWT = frmMilSpec.Controls(strWGT)

If ctrWT >= [WEIGHT SPEC] Then
with ctrWT
.BackColor=
.ForeColor=
End with
Else
with ctrWT
.BackColor=
.ForeColor=
End with
failStatus = "FAIL"
End If

I am trying to use a variable to represent text boxes on a form so that I can
cgahne the background colors of different boxes.

For I = 1 To 2

strWGT = "AVG_WT_" & LTrim(Str(I))

If [Forms]![Mil Spec Data Entry](strWGT) >= [WEIGHT SPEC] Then
[Forms]![Mil Spec Data Entry](strWGT).BackColor = 4259584
[Forms]![Mil Spec Data Entry](srtWGT).ForeColor = -2147483640
Else
[Forms]![Mil Spec Data Entry](strWGT).BackColor = 255
[Forms]![Mil Spec Data Entry](strWGT).ForeColor = 16777215
FailStatus = "FAIL"

End If

I keep getting 'Object doesn't support this property or method' error.

How can I get this to work??
 

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