Value from table into code variable

  • Thread starter Mark Cuthbertson
  • 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
 
N

Nick Coe \(UK\)

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.
 
N

Nick Coe \(UK\)

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.
 
M

Mark Cuthbertson

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
 

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