Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Sub DLVH_5p()

Dim tgRS As New ADODB.Recordset

Dim timeBegin As Date

Dim timeEnd As Date

Dim StrBegin As String

Dim StrEnd As String

Dim strSQL As String

Dim iRow As Integer

Dim tg

Dim en_Print As Boolean

Sheet8.Range("A13", "Y20000").ClearContents ' Xoa du lieu trong bang

timeBegin = Sheet8.Range("D8").Value

timeEnd = Sheet8.Range("D9").Value

StrBegin = "'" & Month(timeBegin) & "/" & Day(timeBegin) & "/" & Year(timeBegin) & " " &
Hour(timeBegin) & ":" & Minute(timeBegin) & "'"

StrEnd = "'" & Month(timeEnd) & "/" & Day(timeEnd) & "/" & Year(timeEnd) & " " & Hour(timeEnd) &
":" & Minute(timeEnd) & "'"

'******** Thong so tram thoi tiet 1 **************

strSQL = "SELECT E3TimeStamp,[Solar_Rad_1],[Solar_Rad_2],[Solar_Panel_Temp],[Air_Temp],


[Wind_Speed]"

strSQL = strSQL & " FROM [DB].[dbo].[MEAS_WSS1] WHERE (E3TimeStamp BETWEEN " & StrBegin & "
AND " & StrEnd & ") ORDER BY E3TimeStamp"

With tgRS
.ActiveConnection = "Provider=SQLOLEDB;User ID=" & User & "; PWD=" & Pass & ";Initial Catalog="
& Cat & ";Data Source=" & Ser & ";"

.Source = strSQL

.Open

End With

iRow = 13

While (Not tgRS.EOF)

Sheet8.Range("A1").Value = tgRS.Fields(0).Value

en_Print = True

If en_Print Then

Sheet8.Range("A" & iRow).Value = Sheet8.Range("A1").Value

Sheet8.Range("B" & iRow).Value = tgRS.Fields(1).Value 'Solar_Rad 1

Sheet8.Range("C" & iRow).Value = tgRS.Fields(2).Value 'Solar_Rad 2

Sheet8.Range("D" & iRow).Value = tgRS.Fields(3).Value 'Solar Panel Temp

Sheet8.Range("E" & iRow).Value = tgRS.Fields(4).Value 'Air Temp

Sheet8.Range("F" & iRow).Value = tgRS.Fields(5).Value 'Wind Speed

End If
iRow = iRow + 1

tgRS.MoveNext

Wend

With tgRS

.Close

End With

You might also like