By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,483 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,483 IT Pros & Developers. It's quick & easy.

A mystery: create table query doesn't create table from code

P: n/a
Hello

Why do you think a create table query doesn't create table from the
following code?

Set myQuery = myDB.QueryDefs("qryCON absent adults previous day log")
myQuery.Execute

If I execute the query myself, it creates the table perfectly well.
When executed from code, an error is 3061: too few parameters. Expected
1.

The query is:

SELECT [qryCON absent students per day].[PERSON_CODE], [qryCON absent
students per day].[DAY], [qryCON absent students per day].[START_TIME],
[qryCON absent students per day].[SBJ_CODE_P], [qryCON absent students
per day].[CAL_OCC_P], [qryCON absent students per
day].[FES_SPONSOR_CODE], [qryRegister Student Comments].[EVENT_DATE],
[qryRegister Student Comments].[Expr1] AS Comment INTO [tblCON absent
students per day]
FROM ([qryCON absent students per day] INNER JOIN [qryCON Absent
students per day >2] ON [qryCON absent students per
day].[PERSON_CODE]=[qryCON Absent students per day >2].[PERSON_CODE])
LEFT JOIN [qryRegister Student Comments] ON [qryCON absent students per
day].[PERSON_CODE]=[qryRegister Student Comments].[StuCode];

As you can see, it is based on 3 other queries. If it works on it's
own, it surely should work from code.

Any help will be greatly appreciated.

Thank you.

Nov 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Galka wrote:
If it works on it's
own, it surely should work from code.
No, if it contains brackets to fix syntax errors and is copied somewhere else,
it *might* work but it's not guaranteed. Avoid syntax errors by only using
alphanumeric characters and the underscore in names, and don't use reserved
words like day as a name. Then see if your query works.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200611/1

Nov 22 '06 #2

P: n/a
Granny Spitz via AccessMonster.com wrote:
Galka wrote:
If it works on it's
own, it surely should work from code.

No, if it contains brackets to fix syntax errors and is copied
somewhere else, it *might* work but it's not guaranteed. Avoid
syntax errors by only using alphanumeric characters and the
underscore in names, and don't use reserved words like day as a name.
Then see if your query works.
Also, queries run in the Access GUI can use the Expression Service to resolve
certain expressions like form references and calls to certain VBA functions.
The same query run in code does not have the Expression Service at its disposal.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Nov 22 '06 #3

P: n/a
Thank you to both of you gentlemen.
Your explanation opened my eyes. I have got such mysteries now and then
over the years and never could understand why.
Galina

Rick Brandt wrote:
Granny Spitz via AccessMonster.com wrote:
Galka wrote:
If it works on it's
own, it surely should work from code.
No, if it contains brackets to fix syntax errors and is copied
somewhere else, it *might* work but it's not guaranteed. Avoid
syntax errors by only using alphanumeric characters and the
underscore in names, and don't use reserved words like day as a name.
Then see if your query works.

Also, queries run in the Access GUI can use the Expression Service to resolve
certain expressions like form references and calls to certain VBA functions.
The same query run in code does not have the Expression Service at its disposal.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Nov 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.