Solved

VB6 - error when deleting a row in MS access

Posted on 2012-12-29
4
449 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

717 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