Avatar of Murray Brown
Murray Brown
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Excel VBA Insert multiple records using all or nothing approach

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?
DatabasesVBASQL

Avatar of undefined
Last Comment
Murray Brown

8/22/2022 - Mon
Éric Moreau

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 Brown

ASKER
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 Moreau

I don't have VBA samples, I thought you already your insert statements ready!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Murray Brown

ASKER
Thanks very much Eric