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

Changing Properties in an array

Status
Not open for further replies.

mustangirl

Programmer
Aug 16, 2001
27
US
Here is a portion of code I have written. I have order count for example = 4. I want it to loop through textboxes (mainstring(I) 1- 12) on my report which are set up as an array. And change the font color until order count = 0.

If i declare Mainstring as a String it will read the value of Mainstring, but it gives me an error message, Invalid Qualifier, I tried Variant, it also reads the data, it does not give me an error message but the text color remains black. If I declare it as a control, it won't even read the value it says Empty when it actually contains data.

Any Suggestions?

Do While INTordercount > 0

If I > INTmainroutetrailercount Then
I = 1
Else
If Mainstring(I) = " " Then
I = I + 1
Else
Mainstring(I).ForeColor = vbRed
INTordercount = INTordercount - 1
I = I + 1
End If
End If

Loop SHAWNDRA CREE JONES,
DATABASE DEVELOPER
TOYOTA MOTOR MANUFACTURING NORTH AMERICA
ERLANGER, KY
 
I think that I know what you want, but your message does not make clear what the elements of "Mainstring()" actually contains.

If we assume that Mainstring() contains the NAMES of textbox controls on a report, then you would access the properties of those controls in the following manner:

For example: There are 4 textbox controls on a report. Their names are txtBox1, txtBox2, txtBox3, txtBox4

If we were to reference these controls directly in code, it would look something like this:

me.txtBox1.forecolor = vbred

If Mainstring(1) = "txtBox1", etc, etc, then we would reference the controls like this:

me(Mainstring(1)).forecolor = vbred

"Me" is a collection of all properties and controls on a form or report. You can reference items in a collection in a similar manner as that of arrays. The big difference is that items in a collection can be referenced by either their indexed position in the collection (0, 1, 13, etc) or by their name property (txtBox1, txtBox2, etc).

I hope this helps.
 
It would be better documentation to explicitly specify the Controls Collection.

Controls(Mainstring(I)).ForeColor = vbRed

Also
If Mainstring(I) = " " Then
will not catch a zero-length string ("")
Maybe you want
If Len(Trim$(Mainstring(I))) = 0 Then

Compare Code (Text)
Generate Sort in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top