title: Clearing a table
body: <p>What I'm trying to do is, while in Excel, use VBA to push data to an existing Access table.  I've been able to do this, but am having one small hiccup.  Before I push the data to access, I want to clear the current data on the Access table, so when the new data from Excel comes in, it is the only data in the Access table.  I really don't know how to write code for Access since the class has been on VBA for Excel.   I've tried several different approaches and each time it doesn't work.  For example, the code that seemed like it should work is</p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>DoCmd.RunSQL "DELETE tblName.* FROM CoversheetTableFourthAttempt
  </code></pre>
  
  <p>but I get an error telling me to define an object.</p>
  
  <p>If you could help me with this, I would really appricate it</p>
  
  <p>I've put my code below for reference.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub AccessFourthMonth()
  
  Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
      ' connect to the Access database
      Set cn = New ADODB.Connection
      cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " &amp; _
          "Data Source=C:\Users\Kent\Documents\MBA\Winter 2009 Semester\MBA 614\Final Project\shilded\testdatabase.mdb"
  
  
  ' open a recordset
  Set rs = New ADODB.Recordset
  
  rs.Open "CoversheetTableFourthAttempt", cn, adOpenKeyset, adLockOptimistic, adCmdTable
  ' all records in a table
  r = 2 ' the start row in the worksheet
  
  Do While Len(Range("A" &amp; r).Formula) &gt; 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("Project") = Range("A" &amp; r).Value
          .Fields("Description") = Range("B" &amp; r).Value
          .Fields("Amount") = Range("C" &amp; r).Value
          .Fields("Date") = Range("D" &amp; r).Value
          .Update ' stores the new record
      End With
      r = r + 1 ' next row
  Loop
  rs.Close
  Set rs = Nothing
  cn.Close
  Set cn = Nothing
  
  End Sub
  </code></pre>