Error when Appending SQL to ADOQuery

Posted on 2004-03-24
Last Modified: 2010-04-06
I am Using Delphi 6 Enterprise under Windows 2000, and am using ADO to connect to an ACCESS 2000 Database.

I basically use ADOQueries to connect to the Access Database and generally have NO problems, except, when I use code similar to the following I get the following error: Project XXXXX.exe has raised exception class EAccessViolation with message 'Access violation at address 1B041851 in module 'msjet40.dll'........ etc...

if qwkTable2.Active then dmMain.qwkTable2.Close;

  qwkTable2.SQL.Append('SELECT Sum(mQuoteDetails.TotalCost) AS SumOfTotalCost, Sum(mQuoteDetails.TaxAmount) AS SumOfTaxAmount');
  qwkTable2.SQL.Append('FROM mQuoteDetails');
  qwkTable2.SQL.Append('GROUP BY mQuoteDetails.JobID, mQuoteDetails.QuoteID');
  qwkTable2.SQL.Append('HAVING ((mQuoteDetails.JobID='+IntToStr(iJobID)+') AND (mQuoteDetails.QuoteID='+IntToStr(iQuoteID)+'))');

Basically the qwkTable2 is a ADOQuery with NO SQL code, which I use as a WORK TABLE, that is SQL can change depending on the function. The error occurs after the first APPEND statement (I have tried OTHER statement types, even simple SELECT statements). I thought that the ADOQuery may be in use, so I added the first line, but still no luck.

If I hard code the above Query into the ADOQuery component it works OK, but when I use the above method I get errors.

Note: I have done this on many occasions with SQL Server, with no problems.

Any help would be greatly appreciated

Question by:pjelias
  • 2
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10666553
Use SQL.Add instead of Append
LVL 12

Accepted Solution

esoftbg earned 125 total points
ID: 10666733
try this:

  with dmMain do
    qwkTable2.Active := False;
    T := ''
       + ' SELECT Sum(mQuoteDetails.TotalCost) AS SumOfTotalCost, Sum(mQuoteDetails.TaxAmount) AS SumOfTaxAmount'
       + ' FROM mQuoteDetails'
       + ' GROUP BY mQuoteDetails.JobID, mQuoteDetails.QuoteID'
       + ' HAVING ((mQuoteDetails.JobID='
       + QuotedStr(IntToStr(iJobID))
       + ') AND (mQuoteDetails.QuoteID='
       + QuotedStr(IntToStr(iQuoteID))
       + '';
    qwkTable2.SQL.Text := T;

Author Comment

ID: 10666830

thanks for the quick response and solution

Question though, why does your code work and not mine ?, yet my code works when using SQL SERVER (I am fairly new to using ACCESS)

LVL 12

Expert Comment

ID: 10666911
I think there is 3 reasons:
1. it must to be a space before: FROM, 'GROUP BY and HAVING
2. it must to be quoted the values of IntToStr(iJobID) and IntToStr(iQuoteID)
3. when I place a breakpoint on the line:     qwkTable2.SQL.Text := T;
applikation stops there an I see the content of T


Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Controlled Assessment GCSE - desperate help needed 4 85
DBGrid or StringGrid ? 6 89
How to load 2 images in same column in Delphi 2 47
Wincontrol not (correctly) drawn 15 38
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question