I have a program that gets data from an sql server but when i add new items the code beggins to have an error
Code:
Private Sub TlSiExcel()
Dim adoRs As New ADODB.Recordset
Dim exl, xlbook, xlsht
Dim strSQl As String, dteFrom As String, dteTo As String, phase As String
dteFrom = Format(dtFrom.Value, "yyyy/mm/dd")
dteTo = Format(dtTo.Value, "yyyy/mm/dd")
If optPhase(0).Value = True Then
phase = 1
Else
phase = 2
End If
strSQl = "select distinct testdate, (select testvalue from qa_wl_tl_results a where paramname ='Silane_Si' and a.tlId = tempd.tlId ) Silane_Si, " & _
"(select testvalue from qa_wl_tl_results a where paramname ='Silane_pH' and a.tlId = tempd.tlId ) Silane_pH, " & _
"(select testvalue from qa_wl_tl_results a where paramname ='Silane_Si 3' and a.tlId = tempd.tlId ) Silane_Si3, " & _
"(select testvalue from qa_wl_tl_results a where paramname ='Silane_pH 3' and a.tlId = tempd.tlId ) Silane_pH3 From " & _
"(select a.tlid,testdate,phase,paramname,testvalue from qa_wl_TlAnalysis a,qa_wl_tl_results b " & _
"where a.tlid= b.tlid and phase ='" & phase & "' and a.tlid not like '%4h%' and (cast(testdate as char(20)) like '%6:00AM' or cast(testdate as char(20)) like '%10:00PM') " & _
"and convert(char(10),testdate,111) between '" & dteFrom & "' and '" & dteTo & "') tempd"
OpenRecSet adoRs, strSQl
If Not adoRs.EOF Then
Set exl = CreateObject("Excel.application")
Set xlbook = exl.Workbooks.Open(App.Path & "\Reports\Monthly.xlt")
Set xlsht = xlbook.Sheets("TLSi")
xlsht.Activate
xlsht.Cells(4, 1).CopyFromRecordset adoRs
exl.Sheets("TRCF").Visible = xlSheetHidden
exl.Sheets("TL12H").Visible = xlSheetHidden
exl.Sheets("TL8H").Visible = xlSheetHidden
exl.Sheets("TL4H").Visible = xlSheetHidden
exl.Sheets("Chrome").Visible = xlSheetHidden
exl.Sheets("EFC").Visible = xlSheetHidden
exl.Sheets("Upinorg").Visible = xlSheetHidden
xlsht.Name = "Phase " & phase
'xlsht.Cells.Select
'xlsht.Cells.EntireColumn.AutoFit
xlsht.range("A4:A65536").Select
exl.Selection.NumberFormat = "m/d/yyyy h:mm AM/PM;@"
xlsht.Cells(4, 1).Select
exl.Application.Visible = True
Else
MsgBox "No Record Found!", vbInformation
End If
adoRs.Close
End Sub
pls check if i have mistake