Question : Excute multiple delete and insert statements in same query

Is there a way to execute multiple delete or insert statements in an Access query? Think of this as an equivalent to a sql server stored procedure.

I have a database in sql server that is used by a windows app. I want to package the database with the windows application installation, so I exported it to Access. The problem is that I have several stored procedures, the functionality of which I need to reproduce. Two of the sps have multiple delete and insert statements I want to replicate in Access; hence, the question above.

Thanks.

P.S. I realize I could simply execute each delete and insert statement from the windows app, but I would like to know if there is a better way.  

Answer : Excute multiple delete and insert statements in same query

>Is there a way to execute multiple delete or insert statements in an Access query?
No.

Just like a SP, you'll have to bundle multiple queries within a transaction. Unline SQL, if code throws an error, you can set an error trap that will work throughout the funciton/sub, instead of doing IF @@ERROR<> 0 after every query.

{using ADO}

On error goto eh

Dim cn as ADODB.Connection
Set cn = Whatever

With cn
   .BeginTrans
   
   .Execute "Query #1"
   .Execute "Query #2"
   .Execute "You get the idea"

End With

'If code makes it to here, then no errors
cn.CommitTrans

ex:
  'Do your housekeeping here, then bail.
  Set cn = Nothing
  exit sub

eh:
  'An error occured.
  msgbox "An error occured: " & err.number & ", " & err.Description, vbOkOnly    '<-- replace this with a real error handler
  cn.RollbackTrans
  goto ex

Random Solutions  
 
programming4us programming4us