LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default clear rows and insert records from recordset on refresh

Hi everyone, I tried posting this a few hours ago but it didn't
appear to load.

What I am trying to achieve is that when I refresh (calculate) the
report, the rows between the headings and totals is deleted and the
new data is inserted. I have seen it done before in other
applications but I am unable to find the answers.

I have created a SQL connection to the access database and it's
filtering when I recalculate the spreadsheet on a value in a cell.
Unfortunately for me, it is not deleting the previous data and
inserting the fresh data.

Can someone provide any further assistance?

The VBA code on doing the SQL connection is below.

Sub import_salaries()
Dim conn As New Connection, rec As New Recordset
Dim ws As Worksheet
Dim sql$, i&

Set ws = ThisWorkbook.Worksheets("Sheet1")

conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
"Data Source=" + ThisWorkbook.Path + "\HR_Occupancy_Table.mdb"

' T3Lookup = ws.Range("CCLOOKUP").Value

sql = "SELECT Employee_No, Employee_Name, Cost_Centre_Description,
Salary_Year, T3_CC_Lookup " & _
"FROM HR_OCCUPANCY WHERE T3_CC_Lookup = " &
ws.Range("CCLOOKUP").Value & " ORDER BY Cost_Centre_Description "


rec.Open sql, conn

While Not rec.EOF
i = i + 1
ws.[A5].Cells(i) = rec!Employee_No
ws.[B5].Cells(i) = rec!Employee_Name
ws.[C5].Cells(i) = rec!Cost_Centre_Description
ws.[D5].Cells(i) = rec!Salary_Year
ws.[E5].Cells(i) = rec!T3_CC_Lookup
rec.MoveNext
Wend
rec.Close: conn.Close


End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
clear rows and insert records from recordset on refresh Forgone Excel Programming 1 July 8th 08 05:24 AM
Code - Clear and Insert & If Statement VBA Noob[_27_] Excel Programming 0 July 20th 06 03:18 PM
Insert Next? Or insert a variable number of records...how? Tom MacKay Excel Discussion (Misc queries) 0 April 20th 06 10:44 PM
Access Recordset Rows to Excel Geoff[_11_] Excel Programming 1 May 25th 05 05:41 PM
Returning the Number of Rows in a Recordset Alex[_14_] Excel Programming 2 November 1st 03 11:14 AM


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"