[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Update in Access dbase from VB6

Posted on 2010-11-28
14
Medium Priority
?
199 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
[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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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…
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…
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…
Suggested Courses

649 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