473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Query works in grid but not in code

The query below works fine when run from the query grid, but generates Error
3051 when run from code. I have stripped out the Where clause, so that
wasn't the problem. I've tried it without the Sum() functions, but still the
same errors.
Could the problem be the complexity of the SQL?
INSERT INTO tArrearsGrouped ( PropNum, SortOrder, LAN, PropName, ShopNum,
TenantName, Arrears1, Arrears2, Arrears3, BF, Receipts, Bal, CurrentCharge,
Var, Archive, Manager, Contact1Tel, SelectRecord, SumofBP, SumofJ,
LesseeName, Comments ) SELECT DISTINCTROW tTenants.PropNum,
tTenants.SortOrder, tTenants.LAN, tProperty.PropName, tTenants.ShopNum,
tTenants.TenantName, qArrearsAmountsGrouped.Arrears1,
qArrearsAmountsGrouped.Arrears2, qArrearsAmountsGrouped.Arrears3,
qArrearsAmountsGrouped.BF, qArrearsAmountsGrouped.Receipts,
qArrearsAmountsGrouped.Bal, qArrearsAmountsGrouped.CurrentCharge,
qArrearsAmountsGrouped.Var, tTenants.Archive, tProperty.Manager,
tTenantDetails.Contact1Tel, tTenantDetails.SelectRecord, IIf([SumBP] Is
Null,0,[SumBP]) AS SumofBP, IIf([SumJ] Is Null,0,[SumJ]) AS SumofJ,
tTenants.LesseeName, qArrearsNotesCurrent.Comments FROM (tProperty INNER
JOIN ((tTenants INNER JOIN qArrearsAmountsGrouped ON tTenants.LAN =
qArrearsAmountsGrouped.LAN) LEFT JOIN qArrearsNotesCurrent ON
qArrearsAmountsGrouped.LAN = qArrearsNotesCurrent.LAN) ON tProperty.PropNum
= tTenants.PropNum) INNER JOIN tTenantDetails ON tTenants.LAN =
tTenantDetails.LAN ORDER BY tTenants.SortOrder;
--
Bob Darlington
Brisbane
Nov 12 '05 #1
5 1504
Sorry, forgot to mention that the SQL included in my post was cut from the
SQL view of the query grid.
I then pasted this into a 'Currentdb.Execute' statement (with line
formatting etc of course).

--
Bob Darlington
Brisbane
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
The query below works fine when run from the query grid, but generates Error 3051 when run from code. I have stripped out the Where clause, so that
wasn't the problem. I've tried it without the Sum() functions, but still the same errors.
Could the problem be the complexity of the SQL?
INSERT INTO tArrearsGrouped ( PropNum, SortOrder, LAN, PropName, ShopNum,
TenantName, Arrears1, Arrears2, Arrears3, BF, Receipts, Bal, CurrentCharge, Var, Archive, Manager, Contact1Tel, SelectRecord, SumofBP, SumofJ,
LesseeName, Comments ) SELECT DISTINCTROW tTenants.PropNum,
tTenants.SortOrder, tTenants.LAN, tProperty.PropName, tTenants.ShopNum,
tTenants.TenantName, qArrearsAmountsGrouped.Arrears1,
qArrearsAmountsGrouped.Arrears2, qArrearsAmountsGrouped.Arrears3,
qArrearsAmountsGrouped.BF, qArrearsAmountsGrouped.Receipts,
qArrearsAmountsGrouped.Bal, qArrearsAmountsGrouped.CurrentCharge,
qArrearsAmountsGrouped.Var, tTenants.Archive, tProperty.Manager,
tTenantDetails.Contact1Tel, tTenantDetails.SelectRecord, IIf([SumBP] Is
Null,0,[SumBP]) AS SumofBP, IIf([SumJ] Is Null,0,[SumJ]) AS SumofJ,
tTenants.LesseeName, qArrearsNotesCurrent.Comments FROM (tProperty INNER
JOIN ((tTenants INNER JOIN qArrearsAmountsGrouped ON tTenants.LAN =
qArrearsAmountsGrouped.LAN) LEFT JOIN qArrearsNotesCurrent ON
qArrearsAmountsGrouped.LAN = qArrearsNotesCurrent.LAN) ON tProperty.PropNum = tTenants.PropNum) INNER JOIN tTenantDetails ON tTenants.LAN =
tTenantDetails.LAN ORDER BY tTenants.SortOrder;
--
Bob Darlington
Brisbane

Nov 12 '05 #2
Please disregard this post. There was a parameter buried in a query inside a
query.
Sorry if anyone had wasted time on this.

--
Bob Darlington
Brisbane
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
The query below works fine when run from the query grid, but generates Error 3051 when run from code. I have stripped out the Where clause, so that
wasn't the problem. I've tried it without the Sum() functions, but still the same errors.
Could the problem be the complexity of the SQL?
INSERT INTO tArrearsGrouped ( PropNum, SortOrder, LAN, PropName, ShopNum,
TenantName, Arrears1, Arrears2, Arrears3, BF, Receipts, Bal, CurrentCharge, Var, Archive, Manager, Contact1Tel, SelectRecord, SumofBP, SumofJ,
LesseeName, Comments ) SELECT DISTINCTROW tTenants.PropNum,
tTenants.SortOrder, tTenants.LAN, tProperty.PropName, tTenants.ShopNum,
tTenants.TenantName, qArrearsAmountsGrouped.Arrears1,
qArrearsAmountsGrouped.Arrears2, qArrearsAmountsGrouped.Arrears3,
qArrearsAmountsGrouped.BF, qArrearsAmountsGrouped.Receipts,
qArrearsAmountsGrouped.Bal, qArrearsAmountsGrouped.CurrentCharge,
qArrearsAmountsGrouped.Var, tTenants.Archive, tProperty.Manager,
tTenantDetails.Contact1Tel, tTenantDetails.SelectRecord, IIf([SumBP] Is
Null,0,[SumBP]) AS SumofBP, IIf([SumJ] Is Null,0,[SumJ]) AS SumofJ,
tTenants.LesseeName, qArrearsNotesCurrent.Comments FROM (tProperty INNER
JOIN ((tTenants INNER JOIN qArrearsAmountsGrouped ON tTenants.LAN =
qArrearsAmountsGrouped.LAN) LEFT JOIN qArrearsNotesCurrent ON
qArrearsAmountsGrouped.LAN = qArrearsNotesCurrent.LAN) ON tProperty.PropNum = tTenants.PropNum) INNER JOIN tTenantDetails ON tTenants.LAN =
tTenantDetails.LAN ORDER BY tTenants.SortOrder;
--
Bob Darlington
Brisbane

Nov 12 '05 #3
Hey Bob,

There is no reason why a valid SQL string wont run in code regardless of
complexity (assuming we are talking about an Access database) so pulling out
the where and sum() will not achieve anything apart from possibly
identifying a syntax error. If you continue to have issues try this method
instead.

1. Save the query (if you havent already done so.)

2. Check that the query will execute. (double click to run).

3. Assuming the query is called 'qryBoBsQuery' and your current db object
is called 'CurrentDB' use this method to execute it:
CurrentDB.Execute CurrentDB.QueryDefs("qryBoBsQuery").SQL,dbFailOnEr ror

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
The query below works fine when run from the query grid, but generates Error 3051 when run from code. I have stripped out the Where clause, so that
wasn't the problem. I've tried it without the Sum() functions, but still the same errors.
Could the problem be the complexity of the SQL?
INSERT INTO tArrearsGrouped ( PropNum, SortOrder, LAN, PropName, ShopNum,
TenantName, Arrears1, Arrears2, Arrears3, BF, Receipts, Bal, CurrentCharge, Var, Archive, Manager, Contact1Tel, SelectRecord, SumofBP, SumofJ,
LesseeName, Comments ) SELECT DISTINCTROW tTenants.PropNum,
tTenants.SortOrder, tTenants.LAN, tProperty.PropName, tTenants.ShopNum,
tTenants.TenantName, qArrearsAmountsGrouped.Arrears1,
qArrearsAmountsGrouped.Arrears2, qArrearsAmountsGrouped.Arrears3,
qArrearsAmountsGrouped.BF, qArrearsAmountsGrouped.Receipts,
qArrearsAmountsGrouped.Bal, qArrearsAmountsGrouped.CurrentCharge,
qArrearsAmountsGrouped.Var, tTenants.Archive, tProperty.Manager,
tTenantDetails.Contact1Tel, tTenantDetails.SelectRecord, IIf([SumBP] Is
Null,0,[SumBP]) AS SumofBP, IIf([SumJ] Is Null,0,[SumJ]) AS SumofJ,
tTenants.LesseeName, qArrearsNotesCurrent.Comments FROM (tProperty INNER
JOIN ((tTenants INNER JOIN qArrearsAmountsGrouped ON tTenants.LAN =
qArrearsAmountsGrouped.LAN) LEFT JOIN qArrearsNotesCurrent ON
qArrearsAmountsGrouped.LAN = qArrearsNotesCurrent.LAN) ON tProperty.PropNum = tTenants.PropNum) INNER JOIN tTenantDetails ON tTenants.LAN =
tTenantDetails.LAN ORDER BY tTenants.SortOrder;
--
Bob Darlington
Brisbane

Nov 12 '05 #4
I've had this happen a couple of times - can't remember why - anyways
the workaround is to save the query and execute it, not the sql
Terry

"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message news:<40*********************@news.optusnet.com.au >...
Sorry, forgot to mention that the SQL included in my post was cut from the
SQL view of the query grid.
I then pasted this into a 'Currentdb.Execute' statement (with line
formatting etc of course).

--
Bob Darlington
Brisbane
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
The query below works fine when run from the query grid, but generates

Error
3051 when run from code. I have stripped out the Where clause, so that
wasn't the problem. I've tried it without the Sum() functions, but still

the
same errors.
Could the problem be the complexity of the SQL?
INSERT INTO tArrearsGrouped ( PropNum, SortOrder, LAN, PropName, ShopNum,
TenantName, Arrears1, Arrears2, Arrears3, BF, Receipts, Bal,

CurrentCharge,
Var, Archive, Manager, Contact1Tel, SelectRecord, SumofBP, SumofJ,
LesseeName, Comments ) SELECT DISTINCTROW tTenants.PropNum,
tTenants.SortOrder, tTenants.LAN, tProperty.PropName, tTenants.ShopNum,
tTenants.TenantName, qArrearsAmountsGrouped.Arrears1,
qArrearsAmountsGrouped.Arrears2, qArrearsAmountsGrouped.Arrears3,
qArrearsAmountsGrouped.BF, qArrearsAmountsGrouped.Receipts,
qArrearsAmountsGrouped.Bal, qArrearsAmountsGrouped.CurrentCharge,
qArrearsAmountsGrouped.Var, tTenants.Archive, tProperty.Manager,
tTenantDetails.Contact1Tel, tTenantDetails.SelectRecord, IIf([SumBP] Is
Null,0,[SumBP]) AS SumofBP, IIf([SumJ] Is Null,0,[SumJ]) AS SumofJ,
tTenants.LesseeName, qArrearsNotesCurrent.Comments FROM (tProperty INNER
JOIN ((tTenants INNER JOIN qArrearsAmountsGrouped ON tTenants.LAN =
qArrearsAmountsGrouped.LAN) LEFT JOIN qArrearsNotesCurrent ON
qArrearsAmountsGrouped.LAN = qArrearsNotesCurrent.LAN) ON

tProperty.PropNum
= tTenants.PropNum) INNER JOIN tTenantDetails ON tTenants.LAN =
tTenantDetails.LAN ORDER BY tTenants.SortOrder;
--
Bob Darlington
Brisbane

Nov 12 '05 #5
Thanks Terry and Andrew.
The problem was a parameter I had buried in a query within the query (see my
earlier post).
Sorry to have wasted your time.

--
Bob Darlington
Brisbane
"Bob Darlington" <bo*@dpcmanAX.com.au> wrote in message
news:40***********************@news.optusnet.com.a u...
The query below works fine when run from the query grid, but generates Error 3051 when run from code. I have stripped out the Where clause, so that
wasn't the problem. I've tried it without the Sum() functions, but still the same errors.
Could the problem be the complexity of the SQL?
INSERT INTO tArrearsGrouped ( PropNum, SortOrder, LAN, PropName, ShopNum,
TenantName, Arrears1, Arrears2, Arrears3, BF, Receipts, Bal, CurrentCharge, Var, Archive, Manager, Contact1Tel, SelectRecord, SumofBP, SumofJ,
LesseeName, Comments ) SELECT DISTINCTROW tTenants.PropNum,
tTenants.SortOrder, tTenants.LAN, tProperty.PropName, tTenants.ShopNum,
tTenants.TenantName, qArrearsAmountsGrouped.Arrears1,
qArrearsAmountsGrouped.Arrears2, qArrearsAmountsGrouped.Arrears3,
qArrearsAmountsGrouped.BF, qArrearsAmountsGrouped.Receipts,
qArrearsAmountsGrouped.Bal, qArrearsAmountsGrouped.CurrentCharge,
qArrearsAmountsGrouped.Var, tTenants.Archive, tProperty.Manager,
tTenantDetails.Contact1Tel, tTenantDetails.SelectRecord, IIf([SumBP] Is
Null,0,[SumBP]) AS SumofBP, IIf([SumJ] Is Null,0,[SumJ]) AS SumofJ,
tTenants.LesseeName, qArrearsNotesCurrent.Comments FROM (tProperty INNER
JOIN ((tTenants INNER JOIN qArrearsAmountsGrouped ON tTenants.LAN =
qArrearsAmountsGrouped.LAN) LEFT JOIN qArrearsNotesCurrent ON
qArrearsAmountsGrouped.LAN = qArrearsNotesCurrent.LAN) ON tProperty.PropNum = tTenants.PropNum) INNER JOIN tTenantDetails ON tTenants.LAN =
tTenantDetails.LAN ORDER BY tTenants.SortOrder;
--
Bob Darlington
Brisbane

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bob Darlington | last post by:
The query below works fine when run from the query grid, but generates Error 3051 when run from code. I have stripped out the Where clause, so that wasn't the problem. I've tried it without the...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: Judy | last post by:
I'm using Access 2003 and was wondering if it is possible to have a paramater selection within a crosstab query so that I wouldn't need to build a new table. I have a select query that I'm using...
9
by: Mike Bridge | last post by:
I am using MS Access 2003, and I typed in a query in SQL view which was working fine. Now when I open it, it gives me the error "Join expression not supported". Apparently, Access "fixed" it for...
2
by: Spartaco | last post by:
I have a dropdown control into a page and a gridview, both are associated to two SqlDataSource controls, one of them is used to fill the DropDownControl, that is meant to be a filter over the query...
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
0
Walt in Decatur
by: Walt in Decatur | last post by:
I have a form which is tied to a table with data for equipment belonging in a particular space (tbl_equpment_data). This form is actually a subform on a main form which also deals with other data...
1
by: v13tn1g | last post by:
so basically..what i have done is created a database, populated it and call that database from the GUI. When a user searches something in the database through the GUI, the result of the query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.