Adding Data to Access Table from Excel 2013 with ADODB (Problem 2)

CarlRostron

New Member
Joined
May 11, 2011
Messages
26
I have submitted problem 1 and this appears to be a similar issue (maybe the same I don't know) but I get a different error message from a different part of my code.

Again I am trying to add some data from Excel to Access but this time I receive an error message:

"Operation must use an updateable query" but I have tried the same text string in Access as a Query using the Query Builder and it has no issues at all.

This is the text string:
UPDATE tblSymbol SET tblSymbol.Beta = 1.6047 WHERE (((tblSymbol.SymbolCode)="LYB"));

Here is the code that runs this:
Code:
Sub AddBetaToDB()
On Error GoTo Err:
  Dim cn As ADODB.connection
  Dim Answer As String
  Dim sql
  Dim Exists As Integer
  Dim counter As Integer


  Set cn = New ADODB.connection


  cn.connectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = " & DBPath & ";Persist Security Info=False;"


  cn.Open


  sql = "UPDATE tblSymbol SET tblSymbol.Beta = " & Round(Range("BetaValue").Value, 4) & " " & _
        "WHERE (((tblSymbol.SymbolCode)='" & symbol & "'));"
  'MsgBox sql
  cn.Execute sql ('FAILS AT THIS LINE)


  cn.Close
  Set cn = Nothing


Exit Sub


Err:
  MsgBox Err.Description
  Exit Sub
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Thanks for your response.

I have since looked at this again now and it appears that an existing Connection in the form of a Table generated from the Import Data from Access wizard was Exclusively locking the database. It was this reason that the update could not happen.

Having since removed the table and rerun the same code published here, it worked without a problem.

I hope this post may help other users.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,242
Members
451,756
Latest member
tommyw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top