I'm not sure how to return the value using the SQL statement?

C

Chris K

I want set Town.Defaultvalue to query value:

Town.DefaultValue = SQL "SELECT TOP 1 JHPclients.County FROM JHPclients
GROUP BY JHPclients.County ORDER BY Count(JHPclients.County) DESC;"

but I'm not sure how to return the value using the SQL statement? Any ideas?
 
C

Chris K

I tried Dlookup which seem to return the correct value, msgbox confirms the
right value ("Leics"), but when I start a new record the county field shows
#Name#

County.DefaultValue = DLookup("[county]", "[top county]")
MsgBox County.DefaultValue

Any thoughts?
 
C

Chris K

I dont know why it didn't work but I changed it to add the formula rather
than the value and it works

County.DefaultValue = "= DLookup('[county]', '[top county]')"


Chris K said:
I tried Dlookup which seem to return the correct value, msgbox confirms
the right value ("Leics"), but when I start a new record the county field
shows #Name#

County.DefaultValue = DLookup("[county]", "[top county]")
MsgBox County.DefaultValue

Any thoughts?


Allen Browne said:
A SQL statement cannot return a value.
You can DLookup() the field in a saved query.

Alternatively you can code like this ELookup() function:
http://allenbrowne.com/ser-42.html
 
K

Ken Snell

You need to wrap the value in " characters when setting the DefaultValue:

County.DefaultValue = Chr(34) & DLookup("[county]", "[top county]") &
Chr(34)

--

Ken Snell
http://www.accessmvp.com/KDSnell/




Chris K said:
I tried Dlookup which seem to return the correct value, msgbox confirms the
right value ("Leics"), but when I start a new record the county field shows
#Name#

County.DefaultValue = DLookup("[county]", "[top county]")
MsgBox County.DefaultValue

Any thoughts?


Allen Browne said:
A SQL statement cannot return a value.
You can DLookup() the field in a saved query.

Alternatively you can code like this ELookup() function:
http://allenbrowne.com/ser-42.html
 
C

Chris K

I can see that now thanks

Ken Snell said:
You need to wrap the value in " characters when setting the DefaultValue:

County.DefaultValue = Chr(34) & DLookup("[county]", "[top county]") &
Chr(34)

--

Ken Snell
http://www.accessmvp.com/KDSnell/




Chris K said:
I tried Dlookup which seem to return the correct value, msgbox confirms
the right value ("Leics"), but when I start a new record the county field
shows #Name#

County.DefaultValue = DLookup("[county]", "[top county]")
MsgBox County.DefaultValue

Any thoughts?


Allen Browne said:
A SQL statement cannot return a value.
You can DLookup() the field in a saved query.

Alternatively you can code like this ELookup() function:
http://allenbrowne.com/ser-42.html

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

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


I want set Town.Defaultvalue to query value:

Town.DefaultValue = SQL "SELECT TOP 1 JHPclients.County FROM
JHPclients GROUP BY JHPclients.County ORDER BY Count(JHPclients.County)
DESC;"

but I'm not sure how to return the value using the SQL statement? Any
ideas?
 

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