Solved

VB6 - error when deleting a row in MS access

Posted on 2012-12-29
4
444 Views
Last Modified: 2012-12-29
Hello all

I have an error with the code bellow when i try to delete a row from my VB6 app

In my VB6 app, i have a textbox called: ID_NUM.

In my ID_NUM textbox, i can put a row ID number from my MS Access table.

But when i click on the delete command, i have this error saying:
Runtime error -2147217913. Data type mismatch in criteria expression.

How can i fix that?

Thanks again for your help


 Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub delete_Click()
    Select Case MsgBox("Do you realy want to delete that record?", vbYesNo Or vbQuestion Or vbSystemModal Or vbDefaultButton1, "Delete...")

    Case vbYes
Set con = New ADODB.Connection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & link_for_base.Caption
        con.Open
        rs.Open "SELECT * FROM [TDM_Rate_form_no1] WHERE ID='" & ID_NUM.Text & "'", con, adOpenForwardOnly, adLockReadOnly

        con.Execute ("DELETE * From [TDM_Rate_form_no1] WHERE ID= '" & ID_NUM.Text & "' ")
        con.Update
        con.Close


    Case vbNo

    End Select
End Sub

Open in new window

0
Comment
Question by:Wilder1626
  • 2
4 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38729702
Is the data type for ID numeric and not String.  If so it should be:
WHERE ID= " & ID_NUM.Text

I don't see where you need to use the recordset (rs) in your code.  It seems you could just shorten it to:
Private Sub delete_Click()
    Select Case MsgBox("Do you realy want to delete that record?", vbYesNo Or vbQuestion Or vbSystemModal Or vbDefaultButton1, "Delete...")

    Case vbYes
        Set con = New ADODB.Connection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & link_for_base.Caption
        con.Open
        con.Execute ("DELETE * From [TDM_Rate_form_no1] WHERE ID= '" & ID_NUM.Text & "' ")
        con.Update
        con.Close
    End Select
End Sub

Open in new window

0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38729703
What are the data types of id and id_num?
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 38729705
Correction to the code I posted:
Private Sub delete_Click()
    Select Case MsgBox("Do you realy want to delete that record?", vbYesNo Or vbQuestion Or vbSystemModal Or vbDefaultButton1, "Delete...")

    Case vbYes
        Set con = New ADODB.Connection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & link_for_base.Caption
        con.Open
        con.Execute ("DELETE * From [TDM_Rate_form_no1] WHERE ID= " & ID_NUM.Text)
        con.Update
        con.Close
    End Select
End Sub

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 38729721
Thank you so much

all work with:

       Set con = New ADODB.Connection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & link_for_base.Caption
        con.Open
        con.Execute ("DELETE * From [TDM_Rate_form_no1] WHERE ID= " & ID_NUM.Text)
        con.Update
        con.Close

Open in new window

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question