OpenRecordset...

M

Mark

Hopefull this will solve it

I have had quite a bit of help from this newsgroup and
from that help, the following VBA quey was produced.

Public Sub Query_Value()

Dim str As String

str = "SELECT Sum([FAOstat].[" &
Form_ElementCalcualtion.Text1 & "]*0.01) AS ProJSupply
FROM (FAOstat INNER JOIN [Food Consumption] ON
FAOstat.Food_code = [Food Consumption].Food_code) INNER
JOIN [Country Total] ON ([Food Consumption].Country_Name
= [Country Total].Country) AND ([Food
Consumption].Food_code = [Country Total].Food_Code);"

MsgBox (str)

Set daoRecordset = CurrentDb.OpenRecordset(str)


End Sub


But the result of the query is not produced (ideally in a
table!). Why is that?

Thanks in advance
mark
 
M

Michel Walsh

Hi,


Because you have built a SELECT query. If you want make a table, build a
MAKE TABLE query. Just two words to add, INTO, a key work, and the
newTableName:


str = "SELECT Sum([FAOstat].[" &
Form_ElementCalcualtion.Text1 & "]*0.01) AS ProJSupply INTO
newTableNameHere
FROM (FAOstat INNER JOIN [Food Consumption] ON
FAOstat.Food_code = [Food Consumption].Food_code) INNER
JOIN [Country Total] ON ([Food Consumption].Country_Name
= [Country Total].Country) AND ([Food
Consumption].Food_code = [Country Total].Food_Code);"


Since this is an ACTION query, we EXECUTE it, rather than opening it:


CurrentDb.Execute str, dbFailOnError





Hoping it may help,
Vanderghast, Access MVP
 
M

Mark

Michel

THANK YOU!!

Not only for the original code but for the correction

With kind regards,
Mark
-----Original Message-----
Hi,


Because you have built a SELECT query. If you want make a table, build a
MAKE TABLE query. Just two words to add, INTO, a key work, and the
newTableName:


str = "SELECT Sum([FAOstat].[" &
Form_ElementCalcualtion.Text1 & "]*0.01) AS ProJSupply INTO
newTableNameHere
FROM (FAOstat INNER JOIN [Food Consumption] ON
FAOstat.Food_code = [Food Consumption].Food_code) INNER
JOIN [Country Total] ON ([Food Consumption].Country_Name
= [Country Total].Country) AND ([Food
Consumption].Food_code = [Country Total].Food_Code);"


Since this is an ACTION query, we EXECUTE it, rather than opening it:


CurrentDb.Execute str, dbFailOnError





Hoping it may help,
Vanderghast, Access MVP



Mark said:
Hopefull this will solve it

I have had quite a bit of help from this newsgroup and
from that help, the following VBA quey was produced.

Public Sub Query_Value()

Dim str As String

str = "SELECT Sum([FAOstat].[" &
Form_ElementCalcualtion.Text1 & "]*0.01) AS ProJSupply
FROM (FAOstat INNER JOIN [Food Consumption] ON
FAOstat.Food_code = [Food Consumption].Food_code) INNER
JOIN [Country Total] ON ([Food Consumption].Country_Name
= [Country Total].Country) AND ([Food
Consumption].Food_code = [Country Total].Food_Code);"

MsgBox (str)

Set daoRecordset = CurrentDb.OpenRecordset(str)


End Sub


But the result of the query is not produced (ideally in a
table!). Why is that?

Thanks in advance
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

Similar Threads

Inconsistant behavior in forms vba module 2
Help with populating a report 8
Need help with Code Please!!! 26
Access Module 15
VBA Code 1
Run Time Error #3021 1

Top