Hi, i need to do samples from different worksheets by time. User input the start time and end time in format hh.hh.
I'm thinking do that by SQL request. So I do the following code
I've got error Run-time error '-2147217913 (80040e07). Type missmatch...'
I guess that it hapenned becouse in SQL expression I used time.
If SQL expression will be
sSQL = "SELECT * FROM " & tableName
my code is working almost good and time column will be holds invalid values.
How to fix that ?
Thanks
I'm thinking do that by SQL request. So I do the following code
Code:
...
Dim startLT As Double
Dim endLT As Double
startLT = ThisWorkbook.Worksheets(1).Range("D7").Value
endLT = ThisWorkbook.Worksheets(1).Range("E7").Value
'converting to hh:mm:ss
Dim startTime As Date
Dim endTime As Date
startTime = CDate(startLT / 24)
endTime = CDate(endLT / 24)
Dim CN As New ADODB.connection
CN.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & fName & _
";Extended Properties=""Excel 12.0;HDR=YES"""
CN.Open
'names of worksheets to processing
Dim names
names = Array("000", "001", "010", "011", "100", "101", "110")
Dim i As Long
Dim sSQL As String
Dim tableName As String
Dim sqlTime As String
sqlTime = "SQLTime" 'column header
For i = 1 To UBound(names, 1)
ActiveWorkbook.Worksheets("Summary").Activate
'clean active worksheet for testing
ActiveSheet.Cells.Select
Selection.Delete xlUp
Selection.Clear
Set RS = Nothing
Set RS = CreateObject("ADODB.Recordset")
tableName = "[" & CStr(names(i)) & "$]"
sSQL = "SELECT * FROM " & tableName & " WHERE " & sqlTime & " BETWEEN '" & startTime & "' AND '" & endTime & "'"
'locals window show me the following
'sSQL ="SELECT * FROM [001$] WHERE SQLTime BETWEEN '3:00:00' AND '8:00:00'"
'startTime=#3:00:00# '<- type is Date
'endtime=#8:00:00# '<- type is Date
MsgBox sSQL
RS.Open sSQL, CN ' <<<< ERROR IS HERE
ActiveWorkbook.Worksheets("Summary").Activate
Range("A1").CopyFromRecordset RS
Next i
...
I've got error Run-time error '-2147217913 (80040e07). Type missmatch...'
I guess that it hapenned becouse in SQL expression I used time.
If SQL expression will be
sSQL = "SELECT * FROM " & tableName
my code is working almost good and time column will be holds invalid values.
How to fix that ?
Thanks