?
Solved

Update in Access dbase from VB6

Posted on 2010-11-28
14
Medium Priority
?
198 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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
Course of the Month14 days, 3 hours left to enroll

801 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