473,624 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"datatype mismatch error" in MS Access

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 = win32com.client .Dispatch("DAO. DBEngine.36") db = engine.OpenData base(r"c:\pytho n-access\db4.mdb" ) rs3 = db.OpenRecordse t("work") rs3 = db.OpenRecordse t("select * from work where ID = 3 ")dept = rs3.Fields("dep t")
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.OpenRecordse t("select * from work where ID

= '%i'" %(idnum))
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
File
"win32com\gen_p y\00025E01-0000-0000-C000-000000000046x0x 5x0.py",
line 508, in OpenRecordset
ret = self._oleobj_.I nvokeTypes(1610 809383, LCID,
1, (9, 0), ((8, 1), (12, 17), (12, 17), (12,
17)),Name,
Type, Options, LockEdit)com_er ror: (-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!
_______________ _______________ ____
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

Jul 18 '05 #1
2 2922

"Stephen Briley" <sd*****@yahoo. com> schrieb im Newsbeitrag
news:ma******** *************** *************** *@python.org...
| 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 =
| win32com.client .Dispatch("DAO. DBEngine.36")
| >>> db =
| engine.OpenData base(r"c:\pytho n-access\db4.mdb" )
| >>> rs3 = db.OpenRecordse t("work")
|
| >>>rs3 = db.OpenRecordse t("select * from work where ID
| = 3 ")
| >>>dept = rs3.Fields("dep t")
| >>>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.OpenRecordse t("select * from work where ID
| = '%i'" %(idnum))

Have you tried it without the single quotes around %i?

Regards,
Vincent Wehren


| Traceback (most recent call last):
| File "<interacti ve input>", line 1, in ?
| File
| "win32com\gen_p y\00025E01-0000-0000-C000-000000000046x0x 5x0.py",
| line 508, in OpenRecordset
| ret = self._oleobj_.I nvokeTypes(1610 809383, LCID,
| 1, (9, 0), ((8, 1), (12, 17), (12, 17), (12,
| 17)),Name,
| Type, Options, LockEdit)com_er ror: (-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!
|
|
| _______________ _______________ ____
| Do you Yahoo!?
| Yahoo! Finance: Get your refund fast by filing online.
| http://taxes.yahoo.com/filing.html
|
Jul 18 '05 #2
Stephen Briley <sd*****@yahoo. com> wrote:

For some reason, my posts are scrubbed as attachments.
That's because you are posting in HTML. Switch back to plain text for
newsgroups and everyone will be much happier.
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...
...
When I try I get the following...
idnum = 3
rs3 = db.OpenRecordse t("select * from work where ID

= '%i'" %(idnum))
Traceback (most recent call last):
...
'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?


Two reasons. First, the sprintf code for numbers is %d, not %i. Second,
you are wrapping the number in single quote marks, which turns it into a
string. Try this:

rs3 = db.OpenRecordse t("select * from work where ID = %d" % idnum)
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #3

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

Similar topics

0
960
by: Zhong Guan | last post by:
I got the error "JIT Debugging failed with the following error: Access denied" with my ASP.NET Project in C# Language, each time when I open the solution, the error notice me, to get rid of it , I've tried methods such as : Add the ASPNET user to the Debugger Users group reset IIS set jitdebugging = true in webconfig file all I've done no use, now I can't continue working by this problem, Is there anybody can help me? I'm so eager and...
2
2887
by: Curten | last post by:
Hi, I want to read data from a txt-file that looks like this: aaa 4 12.45 bbb 3 7.34 ccc 12 3.45 and store the data in an array of structures. The struct and array are defined like this
1
3067
by: ApexData | last post by:
Access2k I WAS getting the following error when using the MID function: Run Time Error '13' Type Mismatch I have a new single form, unbound with 1-button on it that uses the following code: Private Sub Command0_Click() MsgBox MID("ABCDEFG", 1, 1)
5
4388
by: Davros9 | last post by:
Trying to get Regular Expressions working....... ---------------- Public Function SepString(InField As String) As String ''seperates on space and comma Dim RE As New RegExp Dim Matches As Match RE.IgnoreCase = True
10
4562
by: dstorms | last post by:
Hi, I'm trying to create a button on a form that: 1. Takes the ComputerID from the form linked to Table 1, 2. Checks Table 2 for a matching ComputerID, and 3. Opens the query qryEditData, and 4. If no match can be found, adds a new record in Table 2 and enters the ComputerID automatcially. The goal is to create a new record in Table 2 when a new record is created in table 1 and have the ComputerID fields match with a 1-to-1...
3
2505
by: bxscikid | last post by:
I am using VB 6 in order to clear a listbox (lststuff) containing material entered by the user via input boxes. I am trying to utilize a command button which will clear the list for the user. When testing the program, as soon as i click on the command button I receive a "Type mismatch" error. How can I solve this? This is the code I am using: Private Sub cmdclear_Click(Index As Integer) Dim warning As String warning =...
2
1424
by: hdroogendyk | last post by:
Folks: I'm an Access newbie, trying to modify an existing application and running into an error that I don't understand. A tree view control is being loaded from an Access table and the "on error" branch is being triggered for reasons beyond me. How do I find the actual error Access error code ( for which there would presumably be more information available ) that triggered the "on error" ? I have a breakpoint set and don't know what...
3
6786
by: martin DH | last post by:
I would definitely appreciate any help with this problem as soon as possible. Thanks! I have a report that should display the results of a query based on two tables (tblClient and tblResult, linked by ClientID). When trying to open the report I receive the following error: "Data Type Mismatch in Criteria Expression" The report worked before, so as an experiment I created a new table with a structure identical to tblResult (so I...
2
5585
DonRayner
by: DonRayner | last post by:
This one has me stumped. I'm getting a "Type Mismatch" error on one of my forms when it's being opened. It's hapening before the forms "On Open" event, I stuck a msgbox in there to check and I'm getting the error before it opens. The line of code that calls the form from another form is. DoCmd.OpenForm "NonConformanceAdd",,,,acFormAdd,acDialog I get the error, click ok, then the form opens and works exactly how it's supposed to. I even...
0
8168
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8330
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8471
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.