Solved

Search and replace in access dbase VB6

Posted on 2010-09-08
5
314 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Wilder1626
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33625508
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
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 33625595
ok, i will try this and let you know.

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 33625628
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 & "' ")
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33625654
You didn't change any field ....

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

Author Closing Comment

by:Wilder1626
ID: 33631915
Oh perfect.

Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

685 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