473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datatype mismatch problem...

I hope somebody can help me, I have a problem executing this line of
sql:

Dim rstur As New Recordset
Dim sql As String

sql = "SELECT * FROM tblpat WHERE [pturnumber]='" &
Me![pturnumber] & "'"
Set rstur = CurrentDb.OpenR ecordset(sql)

With rstur
If .RecordCount > 0 Then
' Would have some more code in here for duplicating
entry
ElseIf .RecordCount = 0 Then
' Some more code here for adding a new entry to form
End If

End With

I'm trying to create a duplicate set of three fields on a form - only
if the user selects OK on a msg box. This database is for a hospital
system where a patient number may have more than one exam. The
[pturnumber] field is set to be Text in the table and also on the
form. Yet each time I run the code, I get a Data-type mismatch error.
Any suggestions?? It's the smallest, most annoying thing holding the
WHOLE project up!!

Regards,

Sam
Nov 12 '05 #1
1 2958
You don't indicate, but I'm guessing you're using either Access 2000 or
Access 2002.

By default, Access 2000 and Access 2002 use ADO. You're using DAO. From the
fact that the CurrentDb statement doesn't raise an error, you've obviously
added a reference to DAO in your application, but I suspect you didn't
remove the reference to ADO when you did that.

If you have both references, you'll find that you'll need to "disambigua te"
certain declarations, because objects with the same names exist in the 2
models. For example, to ensure that you get a DAO recordset, you'll need to
use Dim rstur as DAO.Recordset (to guarantee an ADO recordset, you'd use Dim
rstur As ADODB.Recordset )

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset

(And I'd definitely lose the New in the declaration)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"Sam Gledhill" <sa***********@ hotmail.com> wrote in message
news:a1******** *************** ***@posting.goo gle.com...
I hope somebody can help me, I have a problem executing this line of
sql:

Dim rstur As New Recordset
Dim sql As String

sql = "SELECT * FROM tblpat WHERE [pturnumber]='" &
Me![pturnumber] & "'"
Set rstur = CurrentDb.OpenR ecordset(sql)

With rstur
If .RecordCount > 0 Then
' Would have some more code in here for duplicating
entry
ElseIf .RecordCount = 0 Then
' Some more code here for adding a new entry to form
End If

End With

I'm trying to create a duplicate set of three fields on a form - only
if the user selects OK on a msg box. This database is for a hospital
system where a patient number may have more than one exam. The
[pturnumber] field is set to be Text in the table and also on the
form. Yet each time I run the code, I get a Data-type mismatch error.
Any suggestions?? It's the smallest, most annoying thing holding the
WHOLE project up!!

Regards,

Sam

Nov 12 '05 #2

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

Similar topics

2
2928
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 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
2124
by: Steve Briley | last post by:
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".&nbsp; Here's an example table that I'm working with... &nbsp; ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name&nbsp;&nbsp;&nbsp; dept 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; steve&nbsp;&nbsp; acct
4
1708
by: c_bowen | last post by:
I am using Visual Studio .NET 2003 with SQL Server 2000. I am trying to insert the date and time into a SQL database by using hour(now). I am having a hard time trying to figure out which datatype to use in SQL to store this value. I have tried using datetime, char, nchar, text and nothing seems to work. Anyone have any ideas? Thanks! Regards, :) Christopher Bowen
1
2488
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. Function DateCalc (blah...) As Variant Do Stuff... If Not IsNull(varNewDate) Then DateCalc = varNewDate End If End Function
6
3397
by: rn5a | last post by:
I am inserting records in a MS-Access database table. The data type of one of the columns named *OrderDate* in the DB table is Date/Time. This is the SQL query I am using to insert the records in the Access DB table: =============================== strSQL = "INSERT INTO Cart (CartID, ProductID, Quantity, Total, OrderDate) VALUES (CID, PID, Qty, TotalAmt, ODate)" oleDbCmd = New OleDbCommand(strSQL, oleDbConn)
2
1560
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 number datatype so its showin me this error Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression. /library/12updbook1.asp, line 128
0
1233
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: FormatNumber(DateDiff("d",DateSerial(Left(, 4),Left(Right(,4),2),Right(,2)),Now()))) if i don't use a criteria, it works fine. when i try to use the criteria <7 is when i get the error. It will show the correct records
9
2227
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 that in the code below to create a value for "intPN". I then need that value to become a number so that I can compare it to a range of years (1983-1987). The code below returns the 4 character year as intended. But I get a Datatype mismatch error...
14
1891
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 that in the code below to create a value for "intPN". I then need that value to become a number so that I can compare it to a range of years (1983-1987). The code below returns the 4 character year as intended. But I get a Datatype mismatch in criteria...
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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
10308
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10076
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
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6729
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
5375
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
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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

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.