Microsoft ACE OLEDB 12.0 to 16.0 - vba

There is an excel macro which uses oledb 12.0, worked fine but now some users experiencing issues. It turned out they don't have version 12.0 anymore, only 16.0. Upon changing the code from 12.0 to 16.0 there is a new error message popping up: "Could not find installable ISAM"
This is the original piece of code:
Dim connection As Object 'New ADODB.connection
Dim rs As Object 'New ADODB.Recordset
Dim query As String '
Dim where_filter As String
Dim counter As Integer
Set connection = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.RecordSet")
connection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & fullpath & _
";Extended Properties=""Excel 12.0;HDR=Yes;"";"
query = "SELECT * FROM [Sheet1$]"
Upon changing to:
connection.Open "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=" & fullpath & _
";Extended Properties=""Excel 16.0;HDR=Yes;"";"
we face the "could not find installable isam" error message.
For the users who has version 12.0 the original code works and the connection string at the locals looks like this:
ConnectionString : "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:\Folder\excelfile.xlsx;Mode=Share Deny None;Jet OLEDB:System database="""
But for the users who have only 16.0 the revised code gives the following connection string at the Locals:
ConnectionString : "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=C:\Folder\excelfile.xlsx;" : String
How I should revise the code to work with version 16?
Thank you!

Related

How to connect to Netezza (PureData System for Analytics) via VBA

I am trying to connect to connect to Netezza using VBA. I have enabled the following:
Microsoft Excel 15.0 Object Library
Microsoft Office 15.0 Object Library
Microsoft ActiveX Data Objects 6.1 Library
Visual Basic for Applications
Here is my code:
Sub NZConn()
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim x As Variant
Set cmd = New ADODB.Command
Set RS = New ADODB.Recordset
cmd.ActiveConnection = "Driver={Netezza " & _
"ODBC};servername=servername;port=####;database=database;" & _
"username=username;password=password;"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandTimeout = 120
cmd.CommandType = adCmdText
x = "Write Query here"
cmd.CommandText = x
Set rs = cmd.Execute
Sheet1.Range("A1").CopyFromRecordset rs
cmd.ActiveConnection.Close
End Sub
I can get the code to run without throwing back an error, but there is nothing that is pasted from the record set, which leads me to believe that is may have something to do with the structure of the connection string.
I have the server, user id, password, database, port, and driver.
Would I need to establish / open an ActiveConnection first?
I was able to figure out the issue on my own. I found that there is a command line builder in the 'Tools' tab in Aginity, which helped specify the exact connection string I needed to connect to Netezza. Once I had this connection string, I was getting an 'architecture mismatch' error. After downloading the 32-bit ODBC drivers for Netezza, the methodology worked perfectly. Here is the updated code below:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim iCols As Integer
Dim DB As String, User As String, PW As String, ConnectionString As String
Dim Server As String, Query As String
Dim SQLTable As Worksheet
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set SQLTable = Sheet1
Server = SQLTable.Cells(2,3).Value
User = SQLTable.Cells(2,4).Value
PW = SQLTable.Cells(2,5).Value
DB = SQLTable.Cells(2,6).Value
Query = SQLTable.Cells(2,7).Value
ConnectionString = "Driver={NetezzaSQL};" & _
"server=" & Server & ";" & _
"UserName=" & User & ";" & _
"Password=" & PW & ";" & _
"Database=" & DB & ";" & _
"Query Timeout=120"
cn.Open (ConnectionString)
rs.Open (Query), cn
For iCols = 0 To RS.Fields.count - 1
Worksheets("Sheet2").Cells(1, iCols + 1).Value = rs.Fields(iCols).Name
Next
Worksheets("Sheet2").Cells(2, "A").CopyFromRecordset rs
rs.Close
cn.Close
NB:
"IBM NETEZZA ODBC DRIVER – 32 BIT" is what I downloaded
"ODBC-DRIVER-FOR-NETEZZA-7-X86" is what showed up in my software center to install
"Name: NetezzaSQL ; Version: 7.00.04.41188 ; Company: www.ibm.com ; File: NSQLODBC.DLL" is what is shown now in my 32-bit 'ODBC Data Source Administrator' window
I think your connection string is ok, and yes you should need to open a connection first.
Like this:
AccessConnect = "Driver={Netezza " & _
"ODBC};servername=servername;port=####;database=database;" & _
"username=username;password=password;"
Dim Conn1 As New adodb.Connection
Conn1.ConnectionString = AccessConnect
Conn1.Open
then it would be
Set RS = Conn1.Execute(x) 'where x is your query

Query MS Excel Table using SQL

I found this code to use sql to query a MS Excel table. However, when I run it I get a message stating that the object "Sheet5$" could not be found. There is a table called "Table" on Sheet 5 of the workbook that I am running the code on.
How can I get this code to work
'Reference: Microsoft ActiveX Data Objects x.x Library
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
'Not the best way to refer to a workbook, but convenient for
'testing. it is probably best to refer to the workbook by name.
strFile = ActiveWorkbook.FullName
'Connection string for 2007/2010
strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFile _
& ";Extended Properties=""Excel 12.0 xml;HDR=Yes;"";"
cn.Open strCon
'SQL query string
sSQL = "SELECT * FROM [Sheet5$]"
rs.Open sSQL, cn

VBA / ADO QUERY Runs on my computer and fails on coworkers computer

The following code works perfectly fine on my computer. I cannot understand why it's not working on another persons computer. Can someone lead me towards ideas that may help trouble shoot this?
The error (with on error commented out) is that the array isn't being loaded with data. Get an error like "either bof or eof is true for the current record"
Also I can tell you if the on error GoTo NEXTT is left on.. it goes there and tries to erase the array and returns a wrong data type error. Makes me think the array is empty.
I checked Conn.State and I can confirm that the connection is open.
Function sbADO(ban_id, upc_id, div_id)
'Must add Activex data objects libaray 2.8
Dim sSQLSting As String
On Error GoTo nextt
Dim Conn As New ADODB.Connection
Dim mrs As New ADODB.Recordset
Dim DBPath As String, sconnect As String
DBPath = ThisWorkbook.FullName
'You can provide the full path of your external file as shown below
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath _
& ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";"
Conn.Open sconnect
sSQLSting = "SELECT * From [data$] where BANNER_ID IN (" & ban_id & ") AND UPC_ID IN (" & upc_id & ") AND DIVISION_ID IN (" & div_id & ") " 'Your SQL Statemnt (Table Name= Sheet Name=[DataSheet$])
mrs.Open sSQLSting, Conn
'=>Load the Data into an array
ReturnArray = mrs.GetRows
''OR''
'=>Paste the data into a sheet
'Sheets("Sheet1").Range("A2").CopyFromRecordset mrs
'Close Recordset
mrs.Close
'Close Connection
Conn.Close
'
Exit Function
nextt:
Erase ReturnArray
'mrs.Close
Conn.Close
'MsgBox (ReturnArray(6, 2)) '(feild, row)
End Function
The problem is because
DBPath = ThisWorkbook.FullName <-- the workbook is set to read only.
Removing read only status fixes the issue.
It seems like you're using ADO to query data in the same workbook? That might be for the purposes of simplifying this problem for SO, but it would be easier and faster to get the array you need by referring to the range directly. But in this answer, I'll assume that you really do want to use ADO.
You're trying to use ADO to open the workbook, but you're not specifying the ConnectionString or Open methods with any read-only arguments. Try making these adjustments:
'Add Mode=Read
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & DBPath & _
";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1"";Mode=Read;"
'Add adLockReadOnly
mrs.Open sSQLSting, Conn, , adLockReadOnly

vba query csv files "could not find installable ISAM" error

I intended to write a macro to query both csv and xml files using Access vba. I do not want to parse csv or xml to a temp table in Access.
Dim dbConnection As ADODB.Connection
Dim rs As ADODB.Recordset
Dim dbConnectionString As String
dbConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sourcefilepath & ";Extended Properties=""csv;HDR=Yes;FMT=Delimited"""
Set dbConnection = New ADODB.Connection
dbConnection.Open dbConnectionString
Set rs = New ADODB.Recordset
strSQL = "SELECT * FROM " & sourceFileName
rs.Open strSQL, dbConnection, 3, 3
rs.Close
dbConnection.Close
I tried the code above and kept getting "could not find installable ISAM" error message.
I also tried:
dbConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
sourcefilefolder & ";Extended Properties=""txt;HDR=Yes;FMT=Delimited"""
It didn't work, either.
Any advice would be appreciated. Thanks in advance.
Click on Tools > References and scroll down to:
Microsoft ? (The question is to select which connection you decide to use.)
And select:
Microsoft ADO (version you want)
and
Microsoft OLE (version you want)
I have found it also helps to select: Microsoft DAO Jet 3.6 even when I don't plan to use it as it supports several older utilties I often call on.

Run time error '3706': Provider cannot be found -Visual Basic

I am trying to connect Visual Basic to MS Access using ADODB. But as I execute my code, it prompts: "Provider cannot be found.It may not be installed properly." But when I check on my directory I've got my "msjetoledb40.dll" installed.
Here is my code:
Dim conn As ADODB.Connection, rec As ADODB.Recordset
Sub sample()
Set conn = New ADODB.Connection
conn.Open ("Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\sample.mdb;Persist Security Info=false;")
End Sub
This would be better:
Sub sample()
Dim conn As ADODB.Connection, rec As ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sample.mdb;"
conn.Open
End Sub
You missed a point.
Microsoft.Jet.OLEDB 4.0 => Microsoft.Jet.OLEDB.4.0
Ref: http://www.connectionstrings.com/.
Confirming the version of your MS Office on which the script is running. If you have installed MS Office 2013 or later, you should revise the connection string from:
Provider=Microsoft.Jet.OLEDB 4.0;Data Source=C:\sample.mdb;Persist Security Info=false;
to:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\sample.mdb;Persist Security Info=false;
At least, this sovled my problem.
My solution:
Error 3706
cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & sPath & ";Persist Security Info=False;"
Just Change 12.0 for 15.0
cs = "Provider=Microsoft.ACE.OLEDB.15.0;Data Source=" & sPath & ";Persist Security Info=False;"
and works, always you must to try change the version of the controller!.