Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Search and delete in access dbase VB6

Posted on 2010-09-08
4
Medium Priority
?
300 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
[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
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33625490
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
ID: 33625518
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 2000 total points
ID: 33625539
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
ID: 33625562
Perfect. Thanks. It's working.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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