Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get append query to run 1

Status
Not open for further replies.
Jul 6, 2005
52
GB
Can anyone tell me what I’m doing wrong? I simply want to run an append query in a global module. I tried two methods:

Method 1: using the INSERT INTO statement (exactly) as follows:

INSERT INTO Budget ( BDateID, BProduct, BQty ) SELECT BudgetDate.BDateID, BudTemp.BProduct, BudTemp.BQty FROM BudgetDate INNER JOIN BudTemp ON BudgetDate.BDate = BudTemp.Bdate

This gives me an “Expected: end of statement” compile error

In fact I get this error when I simply copy and paste Access’s own example from the Help file.

Method 2: create a querydef
The action query is created properly using the above statement but then how do I run it? Using OpenRecordset doesn’t work.

I’ve tried all permutations but nothing seems to solve it.
 
Fastest way is

CurrentProject.Connection.Execute "INSERT INTO Budget ( BDateID, BProduct, BQty ) SELECT BudgetDate.BDateID, BudTemp.BProduct, BudTemp.BQty FROM BudgetDate INNER JOIN BudTemp ON BudgetDate.BDate = BudTemp.Bdate;",,adCmdText+adExecuteNoRecords

onother way

DoCmd.RunSQL "INSERT INTO Budget ( BDateID, BProduct, BQty ) SELECT BudgetDate.BDateID, BudTemp.BProduct, BudTemp.BQty FROM BudgetDate INNER JOIN BudTemp ON BudgetDate.BDate = BudTemp.Bdate"

and for a saved query

DoCmd.OpenQuery YourQueryName

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top