I have recently upgraded my version of excel from Excel 2016 to Excel 365.
I have a VBA code which makes a drop down list more dynamic by running a sql query from a dataset in the same Excel workbook. This code used to work in Excel 2016 but it no longer works in the upgrade:
cn_xl.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & ThisWorkbook.FullName & "; Extended Properties=""Excel 12.0; HDR=Yes"";"
The error is: Cannot update. Database or object is read-only.
The wider context of this code is:
'Connect to the campaign data stored in excel Dim cn_xl As ADODB.Connection Set cn_xl = New ADODB.Connection
cn_xl.Open "Provider=Microsoft.ACE.OLEDB.16.0; Data Source=" & ThisWorkbook.FullName & "; Extended Properties=""Excel 16.0 XLSM; HDR=Yes"";"
Dim sql_xlcm As String
sql_xlcm = "select media_type, timeperiod, control, exposed, uplift, uplift_pct " & _
"from [Campaign_data$A1:I" & s05_cmpgn_data.Cells(Rows.Count, 1).End(xlUp).Row & "] " & _
"where product = 'Offer' " & _
"and metric = '" & ThisWorkbook.Sheets("Customer Averages").DropDowns("Drop Down 6").List(ThisWorkbook.Sheets("Customer Averages").DropDowns("Drop Down 6").ListIndex) & "';"
Dim rs_xlcm As ADODB.Recordset
Set rs_xlcm = New ADODB.Recordset
With rs_xlcm
.ActiveConnection = cn_xl
.Open sql_xlcm
ThisWorkbook.Sheets("Customer Averages").Range("E21").CopyFromRecordset rs_xlcm
.Close
End With
What can I do to fix this?
Thanks