View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Chris Dunigan Chris Dunigan is offline
external usenet poster
 
Posts: 14
Default Deleting records from access using ADO in through Excel

Thanks for all your help. All is becoming clearer!!
I am still having one problem that i wondered if you's help me with.

I have the following code:

-----
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=P:\test.msd"

If testcondition1=whatever then
rs.Open "Table1", cn, adOpenKeyset, adLockOptimistic, adCmdTable
sSQL = "DELETE FROM Table1 WHERE [Month]='7'"
cn.Execute sSQL, lRecordsDeleted, adCmdText
End If
rs.Close

If testcondition2=whatever then
rs.Open "Table2", cn, asOpenKeyset, adLockOptimistic, adCmdTable
sSQL = "DELETE FROM Table2 WHERE [Month]='7'"
cn.Execute sSQL, lRecordsDeleted, adCmdText
End If
rs.Close
-----

In the majority of cases i would expect both testcondition1 and
testcondition2 to be met, therefore there will be deletions from
Table1 an Table2. The code initially works, when testcondition1 is
met the data is deleted from Table1, however when the code gets down
to delete data from Table2 i get the following error:

----
Run-time error '-2147217913(80040e07)':
Data type mismatch in criteria expression
----

This error occurs when the line cn.Execute sSQL, lRecordset, adCmdText
is tried.

Do you have any ideas what is going wrong??

Many thanks in advance.
Chris