literal recordset query (1 Viewer)

VBAhole22

Registered User.
Local time
Today, 10:08
Joined
Jan 18, 2002
Messages
117
I have a line of coding that pulls a value out of a table so that I can set a variable equal to it as follows:
Set rsScore = db.OpenRecordset("tbl", dbOpenSnapshot)
rsScore.FindFirst "NAME= '" & name
val_low = rsScore!LOW_VAL
val_high = rsScore!HIGH_VAL
rsScore.Close

This part works well and gives me the value in the fields "LOW_VAL" and "HIGH_VAL" from the table where the names are equal.

What I want to do now is pull the value from a field in this table that I determine at run-time and have stored in a variable. What I guessed below didn't fly:
val_low = rsScore!strWHATEVER & "_LOW"
val_high = rsScore!strWHATEVER & "_HIGH"

I want to be able to pull the value from the table based on something the user selected (the WHATEVER part).
 

cpod

Registered User.
Local time
Today, 09:08
Joined
Nov 7, 2001
Messages
107
You refer to a field in a recordset using a variable:

val_low = rsScore(strWHATEVER & "_LOW")

If strWHATEVER="ScoreField" then this will reference the field "ScoreField_LOW".
 

VBAhole22

Registered User.
Local time
Today, 10:08
Joined
Jan 18, 2002
Messages
117
Thanks cpod. Sometimes the hardest answers are right there in front of ya!!!
 

Users who are viewing this thread

Top Bottom