Microsoft.Ace.OLEDB.16.0 - excel

Can anyone please help me understand why Microsoft.Ace.OLEDB.16.0 doesn't work on Windows 10 x64 with Office 2016 x86?
I get runtime error -2147467259 (80004005) when the connection to OLEDB 16.0 is opened using the following code:
Public Sub ValidityDateCheck_SRT_Templates()
NameFile = "x"
sConn = "Provider=Microsoft.ACE.OLEDB.16.0;WSS;IMEX=1;RetrieveIds=Yes;" & _
"DATABASE=" & sSHAREPOINT_SITE & ";" & _
"LIST=" & sDEMAND_ROLE_GUID_ML & ";"
Set cn = New ADODB.Connection
Set rst = New ADODB.Recordset
With cn
.ConnectionString = sConn
.Open '--> **HERE I GET THE ERROR**
End With
Rs = "SELECT * FROM [Template Library];"
rst.Open Rs, cn, adOpenStatic, adLockOptimistic
Do Until rst.EOF
If Left(rst![Name], InStr(1, rst![Name], "#") - 1) = TemplateID Then
NameFile = rst![Name]
On Error GoTo Skip
ActualVdate = rst![Validity Date]
TransVdate = rst![Transition Period End]
Exit Do
Else
rst.MoveNext
End If
Loop
Skip:
rst.Close
The interesant part is that in DEBUG, if I use 12.0 first and then change to 16.0 and save, it will open it. Then, if I reopen file, i get same error.
Please help me guys.

Are you using VBA? If so, please ensure you have enabled the Microsoft ActiveX Data Objects 6.1 Library on the reference menu.

Try this;
cn.Open "Provider=Microsoft.Ace.OLEDB.16.0;" & _
"Data Source=" & UserForm2.TextBox32.Text & ";Jet OLEDB:Database Password=1101010;Persist Security Info=False;"

Related

error -2147217865 in Microsoft.ACE.OLEDB provider reading a SharePoint list

Please your help, I have the error -2147217865 in Microsoft.ACE.OLEDB provider reading a SharePoint list with VBA, where the Microsoft Access database engine could not find the object. Sometimes it connects without problems, but at other times it generates the error with the same query.
Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset
mySQL = "SELECT * FROM [" & SPListName & "];"
With cnt
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=1;RetrieveIds=Yes;" & _
"DATABASE=" & SERVERUrl & ";" & _
"LIST={" & SPListID & "}"
.Open
End With
rst.Open mySQL, cnt, adOpenDynamic, adLockOptimistic
I think the problem is with authentication in Sharepoint. Not if you can include the username and password in the connection string.

Excel VBA error "Query ' ' is corrupt" while executing update query using ADODB.Connection & Microsoft.ACE.OLEDB.12.0

I have an update query in Excel 2013 vba.
Till recently it worked.
Now I got the error "Query ' ' is corrupt" in the "adoConn1.Execute" command.
I know there is an Access Issue caused by November Office update.
The problem is that I got the error in Excel and the problematic Office updates
where not installed in my PC.
Can you help me?
strUpdateQuery= "Update [Table$] " & " SET FieldName = " & FieldValue
sConn1 = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & PathDB & "\" & FileNameDB & ";" & _
"Extended Properties=""Excel 12.0;HDR=YES"""
Set adoConn1 = New ADODB.Connection
adoConn1.Open sConn1
adoConn1.Execute strUpdateQuery, flagUpdateResult, adExecuteNoRecords
adoConn1.Close
If Not adoConn1 Is Nothing Then Set adoConn1 = Nothing

Wrong result with AVG() time when hour >24 in ADODB.Recordset

someone can help me to understand why, when I run this code I retreive wrong result (the sample table is an extract of 25K recod) each time when in the range of data we have records with Kpi1-2 > 24H.
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
DBPath = ThisWorkbook.FullName
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
Strsql:Select [DataAttesa] as Data, avg([Kpi1-2]) as nr FROM [db_In$] Where TypeTrasp = 'STD' and [1-2_ESITO] in ('90%','100%','Out of Time','On Going') group by [DataAttesa] Order by [DataAttesa]asc
objRecordset.Open strsql, objConnection, adOpenStatic, adLockReadOnly, adCmdUnspecified
Do Until objRecordset.EOF
debug.print objRecordset.Fields.item("nr")
objRecordset.MoveNext
Loop
objRecordset.Close
UPDATE:
I test this code:
debug.print objRecordset.Fields.item("nr")
in the immediate windows I see: 21/01/1900 11:41:00
if I test tu put the result into a cell:
Cells(20, 7) = objRecordset.Fields.item("nr")
the cells.value will be 22/01/1900 11:41:25
Cells(21, 7) = Format(objRecordset.Fields.item("nr"), "dd/mm/yyyy hh:mm;#")
the cells.value will be 21/01/1900 11:41:25
Only the second it's correct.
Why?!?! wath append?!?
the solution to this problem was discussed in this post:
Difference time view from Excel to VBA
I insert the link if it could help any other user
fabrizio

Read Excel file into ADODB recordset

I have an Excel VBA application that reads information from other excel files using ADODB recordsets. This application was working just fine, but a company software update just broke it (I guess, can't explain otherwise).
Copied below is a stripped down version that replicates the error I'm getting (also shown below). I've tried to review the many posts that reference Microsoft.Jet.OLEDB.4.0, but I'm not sure this is related. They all reference a specific error that I'm not seeing.
The identified error is caused by the CN.Open command. Thanks to comment from Matt'sMug, I have determined that I can execute the connection with no issue, provided the subject workbook is already open in Excel. If it is closed (as it should be), the error returns. Any ideas?
Public Sub GetExcelContent()
Dim Excelbook As String
Dim CN As ADODB.Connection, RS As ADODB.Recordset
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Excelbook = Sheets(1).Cells(4, 3)
Set CN = CreateObject("ADODB.Connection")
Set RS = CreateObject("ADODB.Recordset")
CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= " & Excelbook & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
RS.Open "SELECT * FROM [M2_F$]", _
CN, adOpenStatic, adLockOptimistic, adCmdText
End Sub
So, I have not figured out why the previous provider has ceased to work. However, I was able to switch to an alternate that works just as well. The coding is a little cleaner as well, so I'm happy. Here's my new protocol:
Dim CN as New ADODB.Connection
Dim RS as New ADODB.Recordset
Cstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & Excelbook & _
& "; Extended Properties='Excel 12.0 Xml;HDR=YES';"
CN.Open Cstring
RS.Open "SELECT * FROM [M3_F$]", CN, adOpenStatic, adLockOptimistic, adCmdText

Microsoft Excel 2003 - copying out-of-order descriptions

I have done a thorough search but cannot find an answer for my specific issue, using Microsoft Excel 2003.
I need to copy Column R descriptions (alphanumerical) from one xls spreadsheet (let's call it ssA) to columns L & M in another spreadsheet (ssB), by svc_itm_cde (service item code). There are about 300 svc_itm_cdes.
Three complications:
The svc_itm_cde column in ssA is not in the same order as the one in ssB.
Some of the rows of L & M in the ssB already contain descriptions and must be skipped.
Some of the svc_item_cdes in ssB do not appear in ssA, and vice versa.
A friend helped me export to cvs and begin a Python script, but that was too longwinded. Is there any way to do this with vba code (preferably)?
Many thanks.
This might be an over-complicated way of doing this for 300 records but it's a useful technique for larger datasets...
If you just need to get all of the data together in one place so you can work out which descriptions to keep and which to lose then you could use ADO and join the two data sets together.
Start by going to the Visual Basic Editor (press Alt+F11). Once there use Tools > References to add a reference to "Microsoft ActiveX Data Objects 2.8 Library"
Now Insert > Module and paste in this code:
Option Explicit
Sub master_list()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
' This is the connection string for .xlsx files (Excel 2007 and later)
With cn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=Excel 12.0 Xml;"
.Open
End With
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM [ssA$] LEFT JOIN [ssB$] ON [ssA$].[svc_itm_cde] = " & _
"[ssB$].[svc_itm_cde] UNION ALL SELECT * FROM [ssA$] RIGHT JOIN [ssB$] ON " & _
"[ssA$].[svc_itm_cde] = [ssB$].[svc_itm_cde] " & _
"WHERE [ssA$].[svc_itm_cde] IS NULL;", cn
Dim i As Integer
Dim fld As ADODB.Field
i = 0
' Sheet3 should be a blank sheet that we can output the results to
With Worksheets("Sheet3")
For Each fld In rs.Fields
i = i + 1
.Cells(1, i).Value = fld.Name
Next fld
.Cells(2, 1).CopyFromRecordset rs
End With
rs.Close
cn.Close
End Sub
If you are using Excel 2003 or earlier then the connection string part should be:
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=Excel 8.0;"
.Open
End With

Resources