473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

MS Access datatype mismatch error



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 = win32com.client.Dispatch("DAO.DBEngine.36")
>>> db = engine.OpenDatabase(r"c:\python-access\db4.mdb")
>>> rs3 = db.OpenRecordset("work")






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



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 ?
  File "win32com\gen_py\00025E01-0000-0000-C000-000000000046x0x5x0.py", line 508, in OpenRecordset
    ret = self._oleobj_.InvokeTypes(1610809383, LCID, 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12, 17)),Name, 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 error? I'd really appreciate some help, if anyone has any suggestions.  Thanks!


Choose now from 4 levels of MSN Hotmail Extra Storage - no more account overload!
Jul 18 '05 #1
2 2087
Steve Briley <sd*****@hotmail.com> pisze:
<html><div style='background-color:'>


Sorry, pal. Your message can not be read by some of us. Try again.

--
Jarek Zgoda
Unregistered Linux User #-1
http://www.zgoda.biz/ JID:zgoda-a-chrome.pl http://zgoda.jogger.pl/
Jul 18 '05 #2
In article <ma***************************************@python. org>, Steve
Briley <sd*****@hotmail.com> writes
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 = win32com.client.Dispatch("DAO.DBEngine.36")
db = engine.OpenDatabase(r"c:\python-access\db4.mdb")
rs3 = db.OpenRecordset("work")rs3 = db.OpenRecordset("select * from work where ID = 3 ")
dept = rs3.Fields("dept")
print deptpayroll

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 ?
* File
"win32com\gen_py\00025E01-0000-0000-C000-000000000046x0x5x0.py",
line 508, in OpenRecordset
*** ret = self._oleobj_.InvokeTypes(1610809383, LCID, 1, (9, 0), ((8,
1), (12, 17), (12, 17), (12, 17)),Name, 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 error? I'd really appreciate some
help, if anyone has any suggestions.* Thanks!
Choose now from 4 levels of MSN Hotmail Extra Storage - no more
account overload!


Perhaps you don't need the single quotes around %i. e.g. try:
rs3 = db.OpenRecordset("select * from work where ID = %i" % (idnum))


Regards
--
Ian Parker
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen Briley | last post by:
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...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
1
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
7
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I...
2
by: chirag1989 | last post by:
I m havin an error of datatype mismatch actual here i m askin user to input the code in text box and then searchin the record havin that code in database the problem is the code field Bnum is of...
7
by: mlthomas007 | last post by:
Hi, A client asked for a code book (all fields, descriptions, tables, etc.) from our Access database. Has anyone had to do this? It seems to me there must be a way to extract all this...
0
by: Snoopy33 | last post by:
I have a query that builds a date from a text field with the date imput as yyyymmdd in the query, so i have to piece it together in my expression as follows: exp:...
3
by: shivasusan | last post by:
Hi! I am using for my project ASP and Microsoft Access. start date and end date -- In database (Microsoft Access) i set the datatype is Date/Time. It's display error. The error is below:...
9
by: rscheinberg | last post by:
I am working in Access 2007 attempting to grab 2 characters from a text field named ProjectNumber. After determining what 2 digits to add in front to make it a year, I need to do that. I have done...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.