Hello!
I'm trying to return a record set to a excel 2007 table but having no success, i'm back to basics now trying to return the recordset but cannot even manage that (code below). I know i am reading the record information and the debug.print provides all the correct information as i see in the query editor and what i would expect to be returned to the table/sheet. However when i run the code i get nothing returned to the sheet at all, no error is thrown from the code and the debug.print shows i have all the relevant information. I'd appreciate the forums direction as to what i am doing wrong here, and if anyone has any sage advice as to how to return the data directly to my table (updating the table) would be great.
-----------
Sub updatedata()
' Create a recordset object.
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
GetData.Establish_Connection
With rsPubs
' Extract the required records.
.Open "SELECT tasklist_0.WBS, tasklist_0.Description, tasklist_0.TaskEnd, tasklist_0.Resource FROM mydb.tasklist tasklist_0 WHERE (tasklist_0.ProjectNumber='K60347') AND (tasklist_0.Date={d '2011-02-16'}) AND (tasklist_0.TaskEnd>={d '2011-02-16'} And tasklist_0.TaskEnd<={d '2011-03-16'}) ORDER BY tasklist_0.TaskEnd", conn
Debug.Print rsPubs.GetString
' Copy the records into cell A1 on Sheet1.
Sheet1.Range("A1").CopyFromRecordset rsPubs
' Tidy up
.Close
End With
conn.Close
Set rsPubs = Nothing
Set conn = Nothing
End Sub
------------
I'm trying to return a record set to a excel 2007 table but having no success, i'm back to basics now trying to return the recordset but cannot even manage that (code below). I know i am reading the record information and the debug.print provides all the correct information as i see in the query editor and what i would expect to be returned to the table/sheet. However when i run the code i get nothing returned to the sheet at all, no error is thrown from the code and the debug.print shows i have all the relevant information. I'd appreciate the forums direction as to what i am doing wrong here, and if anyone has any sage advice as to how to return the data directly to my table (updating the table) would be great.
-----------
Sub updatedata()
' Create a recordset object.
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
GetData.Establish_Connection
With rsPubs
' Extract the required records.
.Open "SELECT tasklist_0.WBS, tasklist_0.Description, tasklist_0.TaskEnd, tasklist_0.Resource FROM mydb.tasklist tasklist_0 WHERE (tasklist_0.ProjectNumber='K60347') AND (tasklist_0.Date={d '2011-02-16'}) AND (tasklist_0.TaskEnd>={d '2011-02-16'} And tasklist_0.TaskEnd<={d '2011-03-16'}) ORDER BY tasklist_0.TaskEnd", conn
Debug.Print rsPubs.GetString
' Copy the records into cell A1 on Sheet1.
Sheet1.Range("A1").CopyFromRecordset rsPubs
' Tidy up
.Close
End With
conn.Close
Set rsPubs = Nothing
Set conn = Nothing
End Sub
------------