Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Data type mismatch in criteria expression
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Data type mismatch in criteria expression

 Post Reply Post Reply
Author
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Topic: Data type mismatch in criteria expression
    Posted: 11 December 2003 at 9:45pm

I have these error mesg:

Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.

My code:

if strAlpha1 = "" then         &n bsp;         &n bsp;      
 sql = "Select * FROM customer, cust_businesstype WHERE companyname LIKE 'A%' "
 sql = sql & "OR companyname LIKE 'B%' "
 sql = sql & "AND businesstypeID = '10' "
 sql = sql & "AND companyID = custID "         ;           ;           ;           ;       
 sql = sql & "ORDER BY companyname"             
else         
  if strAlpha1 = "0" then
    sql = "Select * FROM customer, cust_businesstype WHERE ASC(LCASE(left(companyname,1))) not between 97 and 122 "
    sql = sql & "AND businesstypeID = '10' "
    sql = sql & "AND companyID = custID "           ;           ;           ;     
    sql = sql & "ORDER BY companyname"
  else       &n bsp;     
    sql = "Select * FROM customer, cust_businesstype WHERE companyname LIKE '" & strAlpha1 & "%' "
    sql = sql & "OR companyname LIKE '" & strAlpha2 & "%' "           ; 
    sql = sql & "AND businesstypeID = '10' "
    sql = sql & "AND companyID = custID "           ;              
    sql = sql & "ORDER BY companyname"
  end if
end if         &nbs p; 
rs.CursorLocation = 3
rs.open sql, conn

In my access db, custID in customer table is autonumber datatype, companyID in BusinessType table is number datatype.

Can anyone point out what's problem? When I took out the '' in '10' to become just 10, it says

The page cannot be displayed

The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.

Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2003 at 7:41am

I'm having a problem understanding what you are trying to do...

When selecting items from two tables, it's a lot easier to name the two tables so it's easier to read, it's also easier to help you out on.  i.e. is your query supposed to be like:

select * from customer c , cust_businesstype b
where b.companyname like 'A%' or b.companyname like 'B%'
and b.businesstypeid = 10
and b.companyid = c.custid
order by b.companyname

Also, what is the purpose of companyid = custid?

Sorry if these seem like dumb questions, but I can't figure out what you are trying to do from the code above... 

Back to Top
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2003 at 7:45am
Basically, there are 3 tables. a join with b and b join with c.
Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2003 at 10:21am

If there are three tables you are wanting to pull data from, you have to have them all listed in your select statement, i.e.

SELECT a.field, b.field FROM tablea a, tableb b, tablec c where c.field = a.field and b.field2=c.field2

Try adding the third table in your FROM clause and see what happens.  I wonder if your data mismatch is because it doesn't know what one of your variables is in the sql statement.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 12 December 2003 at 12:09pm

well, all over the place you have

sql = sql & "AND businesstypeID = '10'

if "businesstypeID" is a numeric-based column, then comparing it to the string '10' will give you.....  you guessed it "Data Type Mismatch" since they don't indeed match

Contribute to the working anarchy we fondly call the Internet
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.