Set VBA variable the value of a field in a table? (Easy question)

  • Thread starter Thread starter Nitrogen666
  • Start date Start date
N

Nitrogen666

Hey,

This is pretty much my first time using Access (I have only been usin
it for a matter of hours) and i've come onto a small problem.
Basically, in VBA code, how can i give a variable the value of
specific field in a table?

So far i have been able to work out this much:

-SELECT tblSubject.[Subject Reference Code], tblSubject.[Grade A] FRO
tblSubject WHERE (((tblSubject.[Subject Reference Code])=" & Chr(34)
Combo20 & Chr(34) & "));-

Now, if i put the above code into the RowSource of a combo box on
form it works. However, i can't figure out how to use the above cod
so that the returned value goes into a VBA variable. (Setting
variable the value of the combo box is not an option)

I hope i have explained myself clearly and that this will be easy fo
someone to answer.

Thanks
 
First off, you're selecting TWO fields in your select statement. Which one
do you want to assign to the variable?

Once you know that, one way to do it would be:

dim yourvariable as string
yourvariable = dlookup("[FieldYouWant]", "tblSubject", "[Subject Reference
Code]=" & me.Combo20)

Greg
 
Back
Top