We help IT Professionals succeed at work.

Excel VBA Insert multiple records using all or nothing approach

Murray Brown
Murray Brown asked
on
73 Views
Last Modified: 2018-12-19
Hi

I need to insert a few hundred records of data into a SQL database using an all or nothing (or transact rollback) approach.
What Excel VBA code would I use to do this?
Comment
Watch Question

Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
how do you insert the records? By doing multiple INSERT statements? In that case surround the block of statements by BEGIN TRAN / COMMIT TRAN.

Check https://docs.microsoft.com/en-us/sql/t-sql/language-elements/begin-transaction-transact-sql?view=sql-server-2017
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks Eric. Do youboissibly gave an Excel VIA example? I will be looping through Excel rows and doing an SQL insert statement for each one
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Commented:
I don't have VBA samples, I thought you already your insert statements ready!
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much Eric