Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Secret Squirrel
 
Posts: n/a
Default Deleting data in a table from excel export

I have the following code set up to export data from excel to an access
table. How do I add code to delete all the data in the table before the
export? I want to be able to delete all the data in the table so that the
data is not duplicated. This will allow the users to export multiple times
without duplicating records. ( in case they hit the run button more than once
or need to change data after they've exported once).

Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & _
"DBQ=C:\Documents and Settings\My Documents\Work Databases\BC Quality
Action Database.mdb;SystemDB=C:\Documents and Settings\My Documents\Work
Databases\sys.mdw;" & _
"Uid=admin;" & _
"Pwd=password;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "0106EXT", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 6 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("RMA") = Range("A" & r).Value
.Fields("DateNotified") = Range("B" & r).Value
.Fields("DateDispositionMade") = Range("C" & r).Value
.Fields("Branch") = Range("D" & r).Value
.Fields("WO#") = Range("E" & r).Value
.Fields("Customer") = Range("F" & r).Value
.Fields("PO#") = Range("G" & r).Value
.Fields("CustomerPN") = Range("H" & r).Value
.Fields("Qty") = Range("I" & r).Value
.Fields("UnitofMeasure") = Range("J" & r).Value
.Fields("Operator") = Range("K" & r).Value
.Fields("DiscCode") = Range("L" & r).Value
.Fields("DiscrepancyDescription") = Range("M" & r).Value
.Fields("DispCode") = Range("N" & r).Value
.Fields("TotalCost") = Range("O" & r).Value
.Fields("IncCode") = Range("P" & r).Value
.Fields("CostofInc") = Range("Q" & r).Value
.Fields("QRCost") = Range("R" & r).Value
.Fields("RewCost") = Range("S" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop

MsgBox "Data has been uploaded to 0106Ext"
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing


End Sub
Reply
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
Pivot table displays data differently, Excel 2003 Perkyleo Excel Worksheet Functions 1 December 16th 05 04:36 PM
Excel Macro to Copy & Paste [email protected] Excel Worksheet Functions 0 December 1st 05 01:56 PM
AHHHH-Get Data from Multiple Excel workbooks JAA149 Excel Discussion (Misc queries) 5 October 30th 05 05:19 PM
TRYING TO SET UP EXCEL SPREADSHEET ON MY COMPUTER MEGTOM New Users to Excel 5 October 27th 05 03:06 AM
Data Table - does it work with DDE links and Stock Tickers? Post Tenebras Lux Excel Worksheet Functions 0 December 1st 04 05:17 PM


All times are GMT +1. The time now is 07:27 AM.

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

About Us

"It's about Microsoft Excel"