Steve R.
Retired
- Local time
- Today, 13:16
- Joined
- Jul 5, 2006
- Messages
- 5,746
I am using an unbound form that checks all the entries before creating the new record. The DAO code below is what I am currently using to create the new record and works fine. The obvious "downside" is that the entire recordset is opened just to add one record. The "upside" is that the DAO code is "cleaner".
It dawned on me that I could use the SQL code below to achieve the same objective of adding a new record.
Both codes work. My question is which approach would be the preferred method of adding a new record? Any alternatives or preferences?
Code:
Set RST = CurrentDb.OpenRecordset("SELECT * FROM dbo_InspectionTable ORDER BY Recordid", dbOpenDynaset, dbSeeChanges)
RST.AddNew
RST!PermitNumber = Me.Text5
RST!Permittee = Me.Text1
RST!PermitType = Me.Combo11
RST!InspectionDate = Me.Text17
RST!EnterDate = Format(Now(), "short date")
RST.Update
It dawned on me that I could use the SQL code below to achieve the same objective of adding a new record.
Code:
Set DBS = CurrentDb
strValues = "'" & Me.Text5 & "', '" & Me.Text1 & "', '" & Me.Combo11 & "', '" & Me.Text17 & "', '" & Format(Now(), "short date") & "'"
DBS.Execute "Insert into dbo_InspectionTable (PermitNumber, Permittee, PermitType, InspectionDate, EnterDate) VALUES " _
& " (" & (strValues) & ");"
DBS.Close
Both codes work. My question is which approach would be the preferred method of adding a new record? Any alternatives or preferences?
Last edited: