VBA SQL Statement failing after 2016 MS Office Update

erickamiller143

New Member
Joined
Nov 29, 2017
Messages
17
I have a sql statement that my vba queries against itself. This has been working just fine and is properly set up. Since I updates my MS Office and now have 2016 Excel I am getting a Runtime Error ODBC driver does not support the requested properties.

Code:
    strSQL = "SELECT DISTINCT Len([GridData$].[WidthFT]), [GridData$].[WidthFT], [GridData$].[WidthIN] FROM [GridData$] WHERE [GridData$].[Model] = '" & Model & "'"
    Debug.Print strSQL
    Width.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

Debugged Message from Immediate Window:
SELECT DISTINCT Len([GridData$].[WidthFT]), [GridData$].[WidthFT], [GridData$].[WidthIN] FROM [GridData$] WHERE [GridData$].[Model] = '123'

This is exactly correct so not sure how to get around whatever this update did. I would appreciate any advice.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
This is the connection string I have now and is what has ben working for a long time prior to update. I could not see from the link provided where it would be different for 2016 vs previous versions.

Code:
Sub OpenDB()
'This macro creates a connection that will allow Excel to run queries against itself
'OpenDB must be called before any SQL queries can be ran


    If cnn.State = adStateOpen Then cnn.Close  'If the connection is already active, close it and reopen it
    cnn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" & _
    ActiveWorkbook.Path & Application.PathSeparator & ActiveWorkbook.Name   'Connect to the activeworkbook
    cnn.Open
    
End Sub
 
Upvote 0
re: {Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}
1. Try to remove the curly braces - { and }.
2. Also, keep in mind that when you are reading via Excel Driver, the workbook data must be saved first before being read by ODBC driver - because ODBC driver reads the physical file (thus need to save) and not the Excel data in memory.
Good Luck!
 
Upvote 0
re: {Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}
1. Try to remove the curly braces - { and }.
2. Also, keep in mind that when you are reading via Excel Driver, the workbook data must be saved first before being read by ODBC driver - because ODBC driver reads the physical file (thus need to save) and not the Excel data in memory.
Good Luck!


I removed the "{}" and received the error at the same spot. I saved it, closed and re-opened the file before running again. Trying to cover all my bases. I am at a loss.
 
Upvote 0
Your SQL appears to be reading the data only, try to replace adLockOptimistic with adLockReadOnlyIf you really want to update, then add READONLY=0 to connection string:
"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};READONLY=0;DBQ="

Good Luck!
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,580
Members
449,039
Latest member
Arbind kumar

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