Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Search and delete in access dbase VB6

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
Wilder1626
Asked:
Wilder1626
  • 2
  • 2
1 Solution
 
DhaestCommented:
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
 
Wilder1626Author Commented:
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
 
DhaestCommented:
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
 
Wilder1626Author Commented:
Perfect. Thanks. It's working.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now