Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2006, 07:22 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL query on Access db giving error

Hi I am trying to convert my website from SQL to MS Access so that I can keep a functional backup in Access.

On this page, I am getting the following error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Wrong number of arguments used with function in query expression 'isnull(tradeprice,UnitPrice)'.

This is the coresponding area of code producing the error. (All code works perfectly in SQL, but gives this error in Access)

<%
Dim rsSpecial
Dim mstrSql
Dim rsSpecial_numRows
mstrSql = "SELECT ProductID, SubCatagoryID, ProductName, ProductPict, SpecialPrice,"
     if isTradeAccount then
        mstrSql = mstrSql & "isnull(tradeprice,UnitPrice)"
     else
        mstrSql = mstrSql & "UnitPrice"
     end if

  mstrSql = mstrSql & " as UnitPrice, 0 as ProductDetailID FROM Products WHERE Special = 'Yes' and ProductID not in (select ProductID from ProductDetails) union " & _
   "SELECT po.ProductID, po.SubCatagoryID, po.ProductName,pr.Pict as ProductPict, " & _
     "isnull(pr.SpecialPrice,po.SpecialPrice) as SpecialPrice,"
     if isTradeAccount then
        mstrSql = mstrSql & "isnull(pr.tradeprice,pr.UnitPrice)"
     else
        mstrSql = mstrSql & "pr.UnitPrice"
     end if
     mstrSql = mstrSql & " as UnitPrice,pr.ProductDetailID FROM Products po inner join productDetails pr on po.ProductID=pr.ProductID WHERE pr.onSpecial = 'Yes' order by ProductDetailID, SubCatagoryID DESC"

Set rsSpecial = Server.CreateObject("ADODB.Recordset")
rsSpecial.ActiveConnection = MM_connTS_STRING
rsSpecial.Source = mstrSql
rsSpecial.CursorType = 0
rsSpecial.CursorLocation = 2
rsSpecial.LockType = 1
rsSpecial.Open()

rsSpecial_numRows = 0
%>
What should I change to get this to work?
Thanks for you help in advance,
Joe


 
Old November 17th, 2006, 11:06 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I am not sure I understand this line:

if isTradeAccount then

If isTradeAccount what? That may be the error. Usually you waould say:

if isTradeAccount = "..." then

or

if IsNull(isTradeAccount) then
etc.

I am not sure Access can work with it the way you have since If is looking for a condition that doesn't seem to be stated before Then.

Access is ANSI89, and not ANSI92, like SQL, so some of your errors may be with supported syntax.

I would be inclined to create most of my queries in Access itself, and then send parameters to the queries, rather than use complete SELECT statements in your code.

HTH

mmcdonal
 
Old November 17th, 2006, 05:06 PM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi thankyou very much for taking the time to help. I have now resolved the code and it is working...

Joe






Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a query from SQL server to Oracle DB SoCalProgAna SQL Server 2000 7 March 24th, 2006 08:15 AM
SQL count query not giving correct results hman SQL Language 2 March 16th, 2005 07:06 AM
SQL count query not giving correct results hman SQL Server 2000 1 March 15th, 2005 01:15 PM
access db to sql server db mikersantiago Classic ASP Basics 4 November 16th, 2004 03:33 AM
Wildcard characters in query giving trouble programmer_kay ADO.NET 3 March 21st, 2004 10:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.