<html><div style='background-color:'><P>This didn't send right the first time, so I'll try again...</P>
<P>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...<BR>ID      name    dept <BR>1       steve   acct <BR>2       mike    acct <BR>3       george  payroll <BR>4       frank   payroll <BR>>>> import win32com.client <BR>>>> engine = win32com.client.Dispatch("DAO.DBEngine.36") <BR>>>> db = engine.OpenDatabase(r"c:\python-access\db4.mdb") <BR>>>> rs3 = db.OpenRecordset("work") </P>
<P>>>>rs3 = db.OpenRecordset("select * from work where ID = 3 ") <BR>>>>dept = rs3.Fields("dept") <BR>>>>print dept <BR>payroll <BR>The above does exactly what I want, except I'd like to use a variable instead of the number 3.  <BR>When I try I get the following...<BR>>>>idnum = 3 <BR>>>>rs3 = db.OpenRecordset("select * from work where ID = '%i'" %(idnum)) <BR>Traceback (most recent call last): <BR>  File "<interactive input>", line 1, in ? <BR>  File "win32com\gen_py\00025E01-0000-0000-C000-000000000046x0x5x0.py", line 508, in OpenRecordset <BR>    ret = self._oleobj_.InvokeTypes(1610809383, LCID, 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12, 17)),Name, <BR>Type, Options, LockEdit)com_error: (-2147352567, 'Exception occurred.', (0, 'DAO.Database', 'Data type mismatch in <BR>criteria expression.', 'jeterr40.chm', 5003464, -2146824824), None)<BR>The data type for the ID field in the table is "number" so why am I recieving the datatype mismatch error? <BR>I'd really appreciate some help, if anyone has any suggestions.  Thanks!<BR></P></div><br clear=all><hr> <a href="http://g.msn.com/8HMAENUS/2749??PS=">Keep up with high-tech trends here at "Hook'd on Technology."</a> </html>