Hello,
I'm trying to view the results of my code within an excel file, however it keeps getting stuck at the copyrecodset line, saying that the 'object does not recognise this property'.
Please can someone help with a way i can copy and paste the recordset???
My code is as follows:
All i want to do is paste the data at this stage, so i'm sure that it is possible.
OOch
I'm trying to view the results of my code within an excel file, however it keeps getting stuck at the copyrecodset line, saying that the 'object does not recognise this property'.
Please can someone help with a way i can copy and paste the recordset???
My code is as follows:
Code:
Sub OpenCOOQry()
Dim rs As ADODB.Recordset
Dim strSELECT As String
Dim DBRecords As String
Dim objXL As Object, objWorkbook As Object, xlCSV As Object
Dim i As Integer
'create recordset objest
Set rs = New ADODB.Recordset
strSELECT = "SELECT *" & _
"FROM Gas_Hull_COT_PortAnlys " & _
"ORDER BY Gas_Hull_COT_PortAnlys.SiteRefNum, Gas_Hull_COT_PortAnlys.MeterPointRef;"
With rs
.Open strSELECT, CurrentProject.Connection
End With
Set objXL = CreateObject("Excel.Application") ' sets the object as excel
objXL.Application.Visible = True 'allows you to see the excel file
' Get and openthe dbrecords
DBRecords = "C:\WINNT\Profiles\archn01\Desktop\DB Records.xls"
Set objWorkbook = objXL.Application.Workbooks.Open(Filename:=DBRecords)
objXL.Application.displayalerts = False 'Turn off the alerts
With objWorkbook
.Worksheets("Sheet1").Activate
[b][COLOR=red]
.offset(1).copyfromrecordset rs[/color][/b]
.ActiveSheet.Cells("a1").PasteSpecial
For i = 0 To rs.Fields.Count - 1
.offset(0, i) = rs.Fields(i).Name
Next i
End With
End Sub
All i want to do is paste the data at this stage, so i'm sure that it is possible.
OOch