MajP
You've got your good things, and you've got mine.
- Local time
- Yesterday, 22:03
- Joined
- May 21, 2018
- Messages
- 8,904
Which is the better way of adding to a table
I do not know if you can see either method is better. Isladog does a lot of speed comparisons and could answer what is faster, but I am pretty sure the sql method is faster. Better code is code that is understandable, reusable, accurate, less likely to error out, debugable, etc. So would be situation dependent.
The sql string method I used requires you to make sure that the literals are formatted correctly that means a date needs to be "#MM/DD/YYYY#" and strings have to be enclosed in quotes. That requires another step.
rstBreedingProgram("Birthdate").Value = Date()
would work without problem independent of regional settings
Using a Sql string would have to do something like
strSql = "Insert INTO tbl_Pedigree (Birthdate) VALUES (#" & Format(date(),"mm/dd/yyyy") & "#)"
Also if you have nulls in the mix you have to worry about handling them. The recordset method does not require you to do anything different.
There is a third method using a parameter query that may be even better. Gives you the speed of the insert query but the flexibility of the record set to handle nulls, dates, and strings.