Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

please check my syntax

Is this syntax correct?  Its not working for me

For i = 0 To 9
            MR5Names(i).text = rec.Fields![MR5Names(" & i & ")]
Next i

I am using VB6
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

You probably want

MR5Names(i).text = rec.Fields![MR5Names] & i

but it's hard to tell. What is in MR5Names and what should MR5Names(i).Text look like?
That would depend on your declaration of MR5Names. What type is this? Also, what do you mean it's not working? What hapens? What is supposed to happen?
At first glance, it would seem you want:
MR5Names(i).text = rec.Fields!["MR5Names(" & i & ")"]
But without access to the rest of your code, I can't know for sure.
Avatar of al4629740

ASKER

MR5Names is an array

MR5Names(0)
MR5Names(1)
.....

These are the same names both on my Vb6 forma and in my database.  
Yes we realize that but what would one of the members of the array look like and what do you want the textbox to look like? Also as Cluskitt asked, what do you me when you say "It's not working"?
When I use this code it works well

MR5Names(0) = rec.Fields![MR5Names(0)]
I am trying to take this code and loop it 0 thru 9

MR5Names(0) = rec.Fields![MR5Names(0)]
So, what do you want? Do you want to get the value of the field called MR5Names(0), or the value of the field with the name equal to the value of MR5Names(0)? I'm taking another guess here:
MR5Names(i) = rec.Fields![MR5Names(i)]
Then

MR5Names(i) = rec.Fields![MR5Names(i)]

should work.
MR5Names(0) = rec.Fields![MR5Names(0)]

Textbox to database
Ah, ok. What you want is:
MR5Names(i) = rec.Fields!["MR5Names(" & i & ")"]
rec.Fields![MR5Names(0)] = MR5Names(0)



???
When I try that, I get "Item cannot be found in the collection..." error
"When I try that, I get "Item cannot be found in the collection..." error"

When you try what?
Now when I try these

MR5Names(i) = rec.Fields!["MR5Names(" & i & ")"]
 and
MR5Names(i) = rec.Fields![MR5Names(i)]

SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's probable that you want:
MR5Names(i) = rec.Fields!["MR5Names" & i]
It's not usual to have () as part of the field name.
The database has MR5Names(0), MR5Names(1)...

I tried your suggestion earlier and it gave me that error that I stated.  Maybe I should just change the names in the database...
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually this works when I change things around.  Thanks for your help

MR5Names(i) = rec.Fields(("MR5Names" & i))
You got it