passing a variable through ADO?

Okay normally when using ADO, to access a recordset, let's say for example Adodc1.Recordset![fieldname] now what I want to do is set it up so I could send a variable value... how do I do that?  Adodc1.Recordset!(a variable As String)  is that even possible, if not what are the alternatives?  I would like to use a lookup table to pick-up these fieldnames.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Youre going to have to use a case statement...

For example Lets say you have a field called "CustomerName".  You can do this:

Dim X as String

Select Case X
   Case "CustomerAddress"
   Case "CustomerName"
End Select

This is a much easier way. I hope you select this as an answer:

instead of




(use variable for "fieldname")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
twol made a typo! There are no quotes around the variable name.

dim x as string

  x= "SomeFieldName"

  msgbox rs(x)
  msgbox rs.fields(x)
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

TrieuAuthor Commented:
With so many fields coming in, this is definitely the best method.  The first method would work too, but it would mean I have to make way too many select case statements.  This way is very simple for me.  Thanks to both of you.  Thanks to you to emoreau, but I did pick up the fact that the quotes were not required.  I am going to alot the points to twol.

Thanks everyone,
twol's way is also available to you as long as you don't use the rs!fieldname format, however, just remember if the field in the variable does not exist, VB WILL error out and you will need an error handler... Using the case, you get to check the validity of the fieldname before you make the call...

It's your choice...

TrieuAuthor Commented:
mcrider, that is a very good point.  I have created an error handler for that just in case the fieldname doesn't exist or if any other error occurs.  If I didn't have so many different tables and fieldnames to worry about, I would have used your meethod.  If there was a way, I would give you some points too....

If you want to throw a couple of points my way, you can create a new question with the title "FOR MCRIDER ONLY" and I will answer it...  Good-Luck!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.