read from a table

  • Thread starter Thread starter JethroUK©
  • Start date Start date
J

JethroUK©

how do i read a value from a table:

CurrentDb.TableDefs("stats").Fields("from").Value

there's only 1 field ('from') and only 1 record
 
Use either DLookup or a Recordset to read the value. A recordset is normally
the fastest, but with 1 record, it shouldn't make any difference.

Dim rst As DAO.Recorset
Dim db As DAO.Database
Dim strWhatever As String

Set db = CurrentDb
Set rst = db.OpenRecordset("Stats", dbOpenSnapshot)

strWhatever = rst!from
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
tried:

t = CurrentDb.CreateQueryDef(, "SELECT Stats.from FROM Stats")
MsgBox t

still doen't like it - i think it's returning a record set instead of just a
single value
 
purfic - thanx


Allen Browne said:
Try:
=DLookup("[from]", "stats")

For more info, see:
Getting a value from a table: DLookup()
at:
http://allenbrowne.com/casu-07.html

BTW, since FROM is a reserved word in SQL, it's not a good field name.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

JethroUK) said:
how do i read a value from a table:

CurrentDb.TableDefs("stats").Fields("from").Value

there's only 1 field ('from') and only 1 record
 
ignore this - problem solved


JethroUK© said:
tried:

t = CurrentDb.CreateQueryDef(, "SELECT Stats.from FROM Stats")
MsgBox t

still doen't like it - i think it's returning a record set instead of just a
single value
 
is it possible to use sql statement to read a value e.g.

t = CurrentDb.CreateQueryDef(, "SELECT Stats.from FROM Stats")

i'm just not sure how to specify a particular record. maybe:

t = CurrentDb.CreateQueryDef(, "SELECT Top 1 Stats.from FROM Stats")
 
JethroUK© said:
is it possible to use sql statement to read a value e.g.

t = CurrentDb.CreateQueryDef(, "SELECT Stats.from FROM Stats")

i'm just not sure how to specify a particular record. maybe:

t = CurrentDb.CreateQueryDef(, "SELECT Top 1 Stats.from FROM Stats")

There is only 1 record, but if you needed to select 1 from amongst several:

("SELECT Stats.from FROM Stats WHERE ID=" & Me.txtID)

or correct form reference if txtID is not the key value of the record.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top