I have experience coding in several languages (VBA not being one of them) and am trying to teach myself enough VBA to write intelligent macros in Excel and Access. I have gleaned a lot of the necessary code off the internet and managed to figure out how to add Excel records into Access but want to clear out existing Access records in this database first. The relevant code looks like this:
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _"Data Source=C:\Documents and Settings\...\Desktop\testDB.mdb;"
Set rs = New ADODB.Recordset
rs.Open "PartInfo", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.Delete
.Update
End With
The actual ".Delete" command replaces all fields on the first row with "#Deleted" but doesn't actually complete the delete unless I close down the database. Moreover, it does not delete the entire table. I would like to replace this with a command or commands to clear out the whole thing at once. Does anyone know how to delete the contents of a database table wholesale through this ADODB connection?
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _"Data Source=C:\Documents and Settings\...\Desktop\testDB.mdb;"
Set rs = New ADODB.Recordset
rs.Open "PartInfo", cn, adOpenKeyset, adLockOptimistic, adCmdTable
With rs
.Delete
.Update
End With
The actual ".Delete" command replaces all fields on the first row with "#Deleted" but doesn't actually complete the delete unless I close down the database. Moreover, it does not delete the entire table. I would like to replace this with a command or commands to clear out the whole thing at once. Does anyone know how to delete the contents of a database table wholesale through this ADODB connection?