Problem finding a column in a table using variables

C

CD Tom

Here's what i'm trying to do.
Strsql = "select * from master where membernumber = " & Vmbrnumber & ""
set rs = db.openrecordset(strsql)
i = VNumber ' this is a varaible number depending on the column I want to
look up
VTime = rs("Time" & i) ' this should be column time1 if Vnumber = 1

I get a error Item not found in collection.
Can anybody let me know how to do this.
 
J

June7 via AccessMonster.com

When using variables to build a field name, need the Field method of the
recordset, so try:
VTime = rs.Fields("Time" & i)

Would be similar requirement if building control names with a variable, ex:
Me.Controls("tbxData" & i)
 
J

John W. Vinson

Here's what i'm trying to do.
Strsql = "select * from master where membernumber = " & Vmbrnumber & ""
set rs = db.openrecordset(strsql)
i = VNumber ' this is a varaible number depending on the column I want to
look up
VTime = rs("Time" & i) ' this should be column time1 if Vnumber = 1

I get a error Item not found in collection.
Can anybody let me know how to do this.

Try rs.Fields("Time" & i)

But if you have multiple Time fields your table structure is not properly
normalized! It's a good spreadsheet but if you have a one (member) to many
(times) relationship you would do better to have two tables in a one to many
relationship.
 

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