Solved

Update in Access dbase from VB6

Posted on 2010-11-28
14
192 Views
Last Modified: 2012-05-10
Hello all,

I'm trying to update a few data and i have an error.

I want to update "adress and Ville" field.

How can i fix this please?

Thanks
If (a = 6) Then
        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 [Employés] WHERE Nom='" & txtNomemploye1.Text & "'", MyConn, adOpenForwardOnly, adLockReadOnly

  
    If MyRecSet1.EOF = False Then
        MyConn.Execute ( _
            "Update [Employés] SET Adresse= '" & txtAdresse.Text & "' AND " _
            & "Ville ='" & txtVille.Text & "'" _
            & Where _
            & "Nom ='" & txtNomemploye1.Text & "' AND " _
            & "Prénom ='" & txtPrenomEmploye.Text & "'")

Open in new window

0
Comment
Question by:Wilder1626
  • 7
  • 7
14 Comments
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34226581
What error do you get?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226589
This is the error
error.jpg
0
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34226595
replace

& Where _

with

& " Where " _
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 11

Author Comment

by:Wilder1626
ID: 34226610
That is good, no more error.

But it does not change anything also.

Altually, it change "Adresse" with a"0" by default and "Ville" stay the same.
0
 
LVL 8

Accepted Solution

by:
Den_HBR earned 500 total points
ID: 34226627
replace

"Update [Employés] SET Adresse= '" & txtAdresse.Text & "' AND " _
            & "Ville ='" & txtVille.Text & "'" _

with

"Update [Employés] SET Adresse= '" & txtAdresse.Text & "' ," _
            & "Ville ='" & txtVille.Text & "'" _
0
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34226635
and just a hint...
It will not work if there is an ' in 1 off you textboxes.
Better use

replace(txtAdresse.Text,"'","''")
replace(txtVille.Text,"'","''")
replace(txtNomemploye1.Text,"'","''")
replace(txtPrenomEmploye.Text,"'","''")
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 34226636
Thanks for your help. This is great
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226642
What do you mean by:

replace(txtAdresse.Text,"'","''")
replace(txtVille.Text,"'","''")
replace(txtNomemploye1.Text,"'","''")
replace(txtPrenomEmploye.Text,"'","''")
0
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34226647
replace a single quote with 2 single quotes.

Trust me!
Try to use "test'test" as your ville and then try to use "test''test" as your ville
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226669
So i need to do this?

 "Update [Employés] SET Adresse= '" & txtAdresse.Text & "' , & "' ," _
0
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34226699
No.

MyConn.Execute ( _
            "Update [Employés] SET Adresse= '" & replace(txtAdresse.Text,"'","''") & "' ," _
            & "Ville ='" & replace(txtVille.Text,"'","''") & "'" _
            & Where _
            & "Nom ='" & replace(txtNomemploye1.Text,"'","''") & "' AND " _
            & "Prénom ='" & replace(txtPrenomEmploye.Text,"'","''") & "'")
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226715
This is weird cause if i enter in the ville: St-Hubert, it is not working. But if i remove the -, it work.

Do you know why?
0
 
LVL 8

Expert Comment

by:Den_HBR
ID: 34226754
Change your code to


Dim strSQL as String

strSQL = " Update [Employés] "
strSQL = strSQL   & " SET "
strSQL  = strSQL  &  "Adresse= '" & replace(txtAdresse.Text,"'","''")  & "'"
strSQL  = strSQL  & " , "
strSQL  = strSQL  & " Ville ='" & replace(txtVille.Text,"'","''")  & "'"
strSQL  = strSQL  &  " Where "
strSQL  = strSQL  &  " Nom ='" & replace(txtNomemploye1.Text,"'","''") & "'"
strSQL  = strSQL  &  " AND "
strSQL  = strSQL  &  " Prénom ='" & replace(txtPrenomEmploye.Text,"'","''") & "'"

MyConn.Execute (strSQL)



set a breakpoint on MyConn.Execute (strSQL) and post the value of strSQL


0
 
LVL 11

Author Comment

by:Wilder1626
ID: 34226842
Oh perfect

I like that.

Thank you so much
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

792 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