Solved

Search and replace in access dbase VB6

Posted on 2010-09-08
5
311 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

17 Experts available now in Live!

Get 1:1 Help Now