VERSION 5.00 Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MShflxgd.ocx" Begin VB.Form Form1 Caption = "Form1" ClientHeight = 6795 ClientLeft = 60 ClientTop = 345 ClientWidth = 13860 LinkTopic = "Form1" ScaleHeight = 6795 ScaleWidth = 13860 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command2 Caption = "Command2" Height = 870 Left = 6660 TabIndex = 2 Top = 4545 Width = 2085 End Begin VB.CommandButton Command1 Caption = "Command1" Height = 1050 Left = 1440 TabIndex = 1 Top = 4590 Width = 3840 End Begin MSHierarchicalFlexGridLib.MSHFlexGrid MSHFlexGrid1 Height = 3705 Left = 135 TabIndex = 0 Top = 90 Width = 11895 _ExtentX = 20981 _ExtentY = 6535 _Version = 393216 _NumberOfBands = 1 _Band(0).Cols = 2 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Option Compare Text Private Sub Command1_Click() Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Set conn = New ADODB.Connection Set rs = New ADODB.Recordset On Error GoTo errHandler 'conn.Open "Provider=Microsoft.ACE.OLEDB.16.0;" & _ "Data Source=D:\MarkServer\Setup\CustomerCare.xlsx;" & _ "Extended Properties=""Excel 12.0 Xml;HDR=YES""" conn.Open "Provider=Microsoft.ACE.OLEDB.15.0;" & _ "Data Source=D:\MarkServer\Setup\CustomerCare.xlsx;" & _ "Extended Properties=""Excel 12.0 Xml;HDR=YES""" conn.CursorLocation = adUseClient rs.CursorLocation = adUseClient rs.Open "SELECT * FROM [Sheet1$]", conn, adOpenStatic, adLockReadOnly With MSHFlexGrid1 Set MSHFlexGrid1.DataSource = rs End With Set rs.ActiveConnection = Nothing ' Work with rs here... rs.Close conn.Close Set rs = Nothing Set conn = Nothing Exit Sub errHandler: MsgBox "Error " & Err.Number & ": " & Err.Description If rs.State = adStateOpen Then rs.Close If conn.State = adStateOpen Then conn.Close Set rs = Nothing Set conn = Nothing ' Dim conn As ADODB.Connection ' Dim rs As ADODB.Recordset ' Dim strConn As String ' Dim strSQL As String ' ' ' 1. Initialize Objects ' Set conn = New ADODB.Connection ' Set rs = New ADODB.Recordset ' ' conn.Open "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=D:\MarkServer\Setup\CustomerCare.xlsx;" & _ ' "Extended Properties=""Excel 12.0 Xml;HDR=YES""" ' ' Debug.Assert False ' Exit Sub ' ' strSQL = "SELECT * FROM [Sheet1$]" ' rs.Open strSQL, conn, adOpenStatic, adLockReadOnly End Sub ' rs.Close ' conn.Close ' Set rs = Nothing ' Set conn = Nothing Private Sub Command2_Click() Dim cn As ADODB.Connection Set cn = New ADODB.Connection On Error Resume Next 'Provider=Microsoft.ACE.OLEDB.16.0; cn.Open "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=D:\MarkServer\Setup\CustomerCare.xlsx;" & _ "Extended Properties=""Excel 12.0 Xml;HDR=YES""" If Err.Number = 0 Then MsgBox "ACE 16.0 available" Else MsgBox Err.Description End If End Sub