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

Dim cn As ADODB.

Connection
Dim ra As ADODB.Recordset
Dim rb As ADODB.Recordset
Dim rc As ADODB.Recordset
Dim rd As ADODB.Recordset
Dim strconn, s1, s2, s3, s4 As String
Dim book As Object
Private Sub CommandButton1_Click()
Set cn = New ADODB.Connection
Set ra = New ADODB.Recordset
Set rb = New ADODB.Recordset
Set rc = New ADODB.Recordset
Set rd = New ADODB.Recordset
'strconn = "Provider = sqloledb;" & "Data Source=LENOVO-PC\SQLEXPRESS;" & "Initi
al Catalog=TESTATV;"
'"Driver={SQL Server};Server=LENOVO-PC\SQLEXPRESS; Initial Catalog=IMREYS;"
'strconn = "Server=LENOVO-PC\SQLEXPRESS;Database=IMREYS;Trusted_Connection=Yes;"
'strconn = "Driver=SQL Server;Server=LENOVO-PC\SQLEXPRESS;Database=IMREYS;"
strconn = "Provider=sqloledb;Data Source=LENOVO-PC\SQLEXPRESS;Initial Catalog=IM
REYS;Integrated Security=SSPI;"
cn.Open strconn
s1 = "select TOP 1 DateAndTime,Val from MixerOntime"
s2 = "select TOP 1 Val from Pressontime"
s3 = "select TOP 1 Val from FurnaceOntime"
s4 = "select TOP 1 Val from Dryerontime"
ra.Open s1, strconn
rb.Open s2, strconn
rc.Open s3, strconn
rd.Open s4, strconn
Dim fname As Integer
Set xls = CreateObject("EXCEL.APPLICATION")
xls.screenupdating = False
xls.displayalerts = False
'xls.Visible = True
Set book = xls.WorkBooks.Open("D:\SRD.xlsx")
'xls.Worksheets("Sheet1").UsedRange.ClearContents
xls.Worksheets("Sheet1").Range("B7:C7").CopyFromRecordset ra
xls.Worksheets("Sheet1").Range("D7").CopyFromRecordset rb
xls.Worksheets("Sheet1").Range("E7").CopyFromRecordset rc
xls.Worksheets("Sheet1").Range("F7").CopyFromRecordset rd
'Set xlsdd = xls.ActiveWorkbook
'ActiveSheet.Range("C12").CopyFromRecordset rp
book.Save
'xls.SaveAs "D:\Book2.xlsx", Fileformat:=
'Createbackup:=False

book.Close
xls.Quit
'Kill "D:\Book1.xls"
'xls.Close
'MsgBox rp.Fields("Millitm").Value
ra.Close
rb.Close
rc.Close
rd.Close
cn.Close
'UserForm1.Unload
End Sub

You might also like