Solved

SQL Update Excel vba

Posted on 2014-10-27
5
250 Views
Last Modified: 2014-10-27
Hello,
can you please help,
I'm trying to update an email address.
I don't get any errors, but nothing gets updated.

Sub UPDATE_Drivers_Emails()
Dim sh As Worksheet
Set sh = Sheets("Emails_Driver")

    Dim cnn As New adodb.Connection
    Set cnn = New adodb.Connection
    Dim strSQL As String

  ' sTART
cnn.Open "Provider=SQLOLEDB.1;User ID=sa; password=xxxxxxxxx;Initial Catalog=Cccccccccccc;Data Source=Wassim-XPS;"

strSQL = "Update Drivers set Email ='" & sh.[J1].Value & "' where ((DriverNumber = '" & sh.[M1].Value & "'))"
                             
cnn.BeginTrans
cnn.CommitTrans

cnn.Close
Set cnn = Nothing
 MsgBox "Updated"
End Sub
0
Comment
Question by:Wass_QA
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40406897
For starters, add the below line right below your strSQL = line.
Msgbox  strSQL     'or Debug.Print strSQL if you're in code

Open in new window

Then write down what is displayed in this question.

At a glance, if DriverNumber is a number then lose the single quote marks ' surrounding the value.
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40406906
Also, you are missing the line that actually executes it...

cnn.Execute strSQL
0
 

Author Comment

by:Wass_QA
ID: 40406908
Hello,
I dropped the single Quote
I get a message
Update Drivers Set Email = 'xxxxx@xxxxxx.om' where (DriverNumber = 2002)

Nothing gets updated though in SQL,
thanks
0
 

Author Comment

by:Wass_QA
ID: 40406913
thank you
this is what I missed.

cnn.Execute strSQL
0
 

Author Closing Comment

by:Wass_QA
ID: 40406915
Thank you
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Out of stack space (Error 28) 5 24
Sql query 34 22
Three Dimensional Journey Map in Excel 8 28
3rd level dependant list 4 33
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

747 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

12 Experts available now in Live!

Get 1:1 Help Now