Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,557 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,913 people online right now. Registration is fast and FREE... Join Now!




Error Message - Data type mismatch in criteria expression

 
Reply to this topicStart new topic

Error Message - Data type mismatch in criteria expression, Data type mismatch in criteria expression

elba1104
9 Apr, 2008 - 08:13 PM
Post #1

New D.I.C Head
*

Joined: 9 Apr, 2008
Posts: 1

Hello everyone, I have just started learning VB. I got this message when I tried to delete one of the record. When I click on Yes button this message - Data type mismatch in criteria expression- appears. Please help.


vb

Private Sub cmdDelete_Click()
Dim pstDeleteMsg As String
Dim pinResponse As Integer
Dim pstDeleteDoctorsSQL As String
Dim prsDeleteDoctors As New ADODB.Recordset
Dim Delete As String
pstDeleteMsg = "Are you sure that you want to remove this doctors records?"
pinResponse = MsgBox(pstDeleteMsg, vbCritical + vbYesNo, "Delete Doctor?")
If pinResponse = vbYes Then
'**Open a recordset that contains the selected Doctor record to be deleted
pstDeleteDoctorsSQL = " SELECT * " & _
" FROM tblDoctor" & _
" WHERE DocNum = '" & txtDocNum.Text & "'"

prsDeleteDoctors.Open pstDeleteDoctorsSQL, gcnTDLabs, adOpenStatic, adLockOptimistic, adCmdText
prsDeleteDoctors.Delete
prsDeleteDoctors!DocStatus = False
Delete = prsDeleteDoctors!DocStatus
prsDeleteDoctors.Close
Set prsDeleteDoctors = Nothing
mrsDoctors.Requery
Call DisplayData
End If
End Sub


EDIT: Please use code tags => code.gif

This post has been edited by PsychoCoder: 9 Apr, 2008 - 08:17 PM
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Error Message - Data Type Mismatch In Criteria Expression
9 Apr, 2008 - 08:15 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Can you perform the Sql statement manually? Or does it give you a similar error?

code.gif
User is online!Profile CardPM
+Quote Post

PsychoCoder
RE: Error Message - Data Type Mismatch In Criteria Expression
9 Apr, 2008 - 08:26 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
The error is in the way you're passing the ID to the database. You have single quotes around the ID, which is an integer data type. The single quotes are telling SQL that the value is a varchar (or char) data type, thus causing your data type mismatch problem. Also, from what I remember about using line continuations in VB6 you have them wrong. In version 6.0 you dont use a & with the continuation, your statement (with the above modifications) should look like


vb

pstDeleteDoctorsSQL = " SELECT * " _
" FROM tblDoctor" _
" WHERE DocNum = " & txtDocNum.Text



PS: Why are you using a SELECT statement when deleting a record? That is using unnecessary resources. You should just go straight to the DELETE. Just my 2¢ smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:21PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month