Retrieving data from a changing field using ADO

R

rael_lucid

Hi,
Subject is extremely vague, let me explain:

Have a table with the following fields:
ItemID (Pkey)
Price1
Price2
....
Price 10

I have some code which is used to retrieve a specific price for a specific
item. The price returned is dependent on user input. ie: The user will
request "Price1", or "Price7" etc

Is it possible in VBA to retrieve the requested field using code similar to
the following:

Function GetPrice(ItemID as long) as Double
....
rsTemp.Open "SELECT * FROM ItemPrices WHERE ItemID = " & {User Entered},
CurrentProject.Connection
....
GetPrice = rsTemp! & {String Variable} ******* THIS IS THE LINE
OF CONCERN
....
End Function

Hopefully that is enough info to advise. Let me know if you need more.

Thanks

Rael
 
B

Brendan Reynolds

The syntax would be ...

rst.Fields(StringVariableHere)

.... or, because Fields is the default property of the Recordset object, you
can use ...

rst(StringVariableHere)
 
R

rael_lucid

Thanks Brendan.
I have amended the code and will run some tests tomorrow with the data.

Rael
 

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