Solved

Search and delete in access dbase VB6

Posted on 2010-09-08
4
292 Views
Last Modified: 2012-05-10
Hello all,

I have a code where i can same data do my access dbase. Code bellow.

But what i need to do know is to find the text from my "txtNomDuProduit1" (Product name in column 2 of my access dbase) and delete that entire row for that product.

How can i do that please?

Thanks for your help.


'Insert data in Microsoft Access Data Base
    Dim MyConn As ADODB.Connection
    Dim MyRecSet1 As New ADODB.Recordset

    Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open "SELECT * FROM [Description produit] WHERE Produits='" & txtNomDuProduit1.Text & "'", MyConn, adOpenForwardOnly, adLockReadOnly


    If MyRecSet1.EOF Then
        MyRecSet1.close
        Set MyRecSet1 = MyConn.Execute( _
          "INSERT INTO [Description produit]  (Produits, Tube, Bouchon, Oring, Coût_unitaire, Par_tranche_de, Opération_1, Opération_2, Opération_3, Nombre_étape ) VALUES ( '" & _
          txtNomDuProduit1.Text & _
          "' , '" & txtTube1.Text & "' ,  '" & txtBouchon1.Text & "' ,'" & txtOring1.Text & "' ,'" & txtCout_unitaire.Text & "' ,'" & txtParTranche.Text & "' , '" & ComOpération1.Text & _
          "' , '" & ComOpération2.Text & "' ,'" & ComOpération3.Text & _
          "' , '" & ComNombreD.Text & "' )")
        MsgBox "Vos nouvelles quantités ont été enregistrées."  ', vbCritical, "Succesful adding"

Open in new window

product-db.jpg
0
Comment
Question by:Wilder1626
  • 2
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
You can execute a delete-statement (but this will delete all the rows where the productname is equal to what you entered). If not found, nothing will be done

MyConn.Execute( _
          "DELETE [Description produit] WHERE  Produits = '" & txtNomDuProduit1.Text & "' ")
0
 
LVL 11

Author Comment

by:Wilder1626
Comment Utility
So something like this?

 Dim MyConn As ADODB.Connection
    Dim MyRecSet1 As New ADODB.Recordset

    Set MyConn = New ADODB.Connection
    MyConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;;Data Source=" & Form4.txtBaseDe.Text
    MyRecSet1.Open "SELECT * FROM [Description produit] WHERE Produits='" & txtNomDuProduit1.Text & "'", MyConn, adOpenForwardOnly, adLockReadOnly

   MyConn.Execute ( _
          "DELETE [Description produit] WHERE  Produits = '" & txtNomDuProduit1.Text & "' ")


If so, i have a syntax error.


0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
Comment Utility
Where do you have the error ?

Ok, I see it now. It's access. Try the following:

MyConn.Execute ( _
          "DELETE * From [Description produit] WHERE  Produits = '" & txtNomDuProduit1.Text & "' ")
0
 
LVL 11

Author Closing Comment

by:Wilder1626
Comment Utility
Perfect. Thanks. It's working.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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