• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

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
0
al4629740
Asked:
al4629740
  • 10
  • 5
  • 5
  • +1
2 Solutions
 
Martin LissRetired ProgrammerCommented:
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?
0
 
CluskittCommented:
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.
0
 
al4629740Author Commented:
MR5Names is an array

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
al4629740Author Commented:
MR5Names(0)
MR5Names(1)
.....

These are the same names both on my Vb6 forma and in my database.  
0
 
Martin LissRetired ProgrammerCommented:
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"?
0
 
al4629740Author Commented:
When I use this code it works well

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

MR5Names(0) = rec.Fields![MR5Names(0)]
0
 
CluskittCommented:
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)]
0
 
Martin LissRetired ProgrammerCommented:
Then

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

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

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



???
0
 
al4629740Author Commented:
When I try that, I get "Item cannot be found in the collection..." error
0
 
Martin LissRetired ProgrammerCommented:
"When I try that, I get "Item cannot be found in the collection..." error"

When you try what?
0
 
al4629740Author Commented:
Now when I try these

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

0
 
CluskittCommented:
Does your database have the fields MR5Names(0), MR5Names(1)... or MR5Names0, MR5Names1...?
Try it by bits:
The array is, I'm assuming, an array of textboxes. In VB6, text is the default property, so you don't need to declare it. So, MR5Names(i) = is the correct thing to do.
Now, you want to get a field from a database. So, MR5Names(i) = rec.Fields![] is correct.
All that remains is: What is the name of the field. You need a string, so something like:
"MR5Names(0)". Once you get that name right, just replace the 0 with " & i & "
Something like:
MR5Names(i) = rec.Fields!["MR5Names(" & i & ")"]
0
 
CluskittCommented:
It's probable that you want:
MR5Names(i) = rec.Fields!["MR5Names" & i]
It's not usual to have () as part of the field name.
0
 
al4629740Author Commented:
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...
0
 
Brook BraswellApplication Development ManagerCommented:
I think I see what you are saying here...
try this

For i = 0 To 9
            MR5Names(i).text = rec.Fields("MR5Names(" & i & ")")
Next i
0
 
al4629740Author Commented:
Actually this works when I change things around.  Thanks for your help

MR5Names(i) = rec.Fields(("MR5Names" & i))
0
 
al4629740Author Commented:
You got it
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 10
  • 5
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now