"datatype mismatch error" in MS Access

Stephen Briley sdb1031 at yahoo.com
Fri Feb 6 03:43:42 CET 2004

For some reason, my posts are scrubbed as attachments.
 Lets hope that sending from the yahoo account works.

I'm new to Python and I'm trying to do some database
work with MS Access, but I can't seem to get around a
 "datatype mismatch error".  Here's an example table
that I'm working with...

ID      name    dept 
1       steve   acct 
2       mike    acct 
3       george  payroll 
4       frank   payroll 
>>> import win32com.client 
>>> engine =
>>> db =
>>> rs3 = db.OpenRecordset("work") 

>>>rs3 = db.OpenRecordset("select * from work where ID
= 3 ") 
>>>dept = rs3.Fields("dept") 
>>>print dept 

The above does exactly what I want, except I'd like to
use a variable instead of the number 3.  
When I try I get the following...

>>>idnum = 3 
>>>rs3 = db.OpenRecordset("select * from work where ID
= '%i'" %(idnum)) 
Traceback (most recent call last): 
  File "<interactive input>", line 1, in ? 
line 508, in OpenRecordset 
    ret = self._oleobj_.InvokeTypes(1610809383, LCID,
1, (9, 0), ((8, 1), (12, 17), (12, 17), (12,
Type, Options, LockEdit)com_error: (-2147352567,
'Exception occurred.', (0, 'DAO.Database', 'Data type
mismatch in 
criteria expression.', 'jeterr40.chm', 5003464,
-2146824824), None)

The data type for the ID field in the table is
"number" so why am I recieving the datatype mismatch
I'd really appreciate some help, if anyone has any
suggestions.  Thanks!

Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.

More information about the Python-list mailing list