Solved

VB6 - error when deleting a row in MS access

Posted on 2012-12-29
4
439 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
Comment Utility
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
Comment Utility
What are the data types of id and id_num?
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now