Avatar of Wilder1626
Wilder1626
Flag for Canada asked on

Search and replace in access dbase VB6

Hello all,

I have a code that i use to save data in an Microsoft Access data base. Code bellow.

But now, i want to have a code that would search for the text in "txtNomDuProduit1"  (Name of a product in column 2 of my access db. and it would save all modification in the same row.

How can i do this please?

Thanks again 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
Visual Basic Classic

Avatar of undefined
Last Comment
Wilder1626

8/22/2022 - Mon
Dirk Haest

For your update-query: which field is unique ? I assume you have a productID or something

MyConn.Execute( _
          "UPDATE [Description produit]  SET " & _
          " Produits = '" & txtNomDuProduit1.Text & "', " & _
          " Tube = '" & txtNomDuProduit1.Text & "', " & _
           "  ... " & _
           " where ProductID = " & YOURID_HERE
Wilder1626

ASKER
ok, i will try this and let you know.

Wilder1626

ASKER
I have try this but i have an syntaxe error

 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 ( _
   "Update [Description produit] WHERE  Produits = '" & txtNomDuProduit1.Text & "' ")
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Dirk Haest

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wilder1626

ASKER
Oh perfect.

Thanks