473,396 Members | 1,847 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,396 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 1505
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.