Value from table into code variable

  • Thread starter Thread starter Mark Cuthbertson
  • Start date Start date
M

Mark Cuthbertson

Hello,

I need to take a value from a table and use it as a
variable in my code. But I don't know how to get the
value into the variable.

I'm not an experienced coder and am sure I am missing
something simple.

The table I have has two fields, 'ID' and 'Value'. Where
ID = 2 I need to collect the Value and place it into
myVariable. What is the syntax to do this?

Thank you for any help,

Mark
 
Check DLookup() in the Help. Something like the following
should do it, substitute your variable and table name in the
appropriate places.

varYourVariable = DLookup("Value", "tblYourTable","ID = 2")

Alternatively you could open either a DAO or ADO recordset
based on an appropriate bit of SQL and get it from there,
but that's a bit long winded if you only need the one value.
 
Oh BTW, try using something other than 'Value' for your
field name. I've a feeling it might be a reserved word in
Access and you might run into trouble with it later.
 
Hi Nick, thank you for this I'll give it a whirl, sounds
perfect. I am using different field names to these...I
just used simple descriptive ones for the purposes of my
question!

Mark
 
Back
Top