Scottish_Anatomist
New member
- Local time
- Today, 22:12
- Joined
- Nov 18, 2015
- Messages
- 7
Hey Everyone,
Not so much a problem as curiosity. While going through all the code I've written for a project over the last year, I noticed that I've used two different methods to achieve the same result to add and edit/update records in tables. It seems that at the beginning of the project I used one and for some reason a few months ago switched to another.
Namely:
Working with record set objects -
and using SQL action queries
Now, I know there are many ways to accomplish the same thing, especially when programming, however I was wondering which you preferred to use in your VBA coding and why?

Not so much a problem as curiosity. While going through all the code I've written for a project over the last year, I noticed that I've used two different methods to achieve the same result to add and edit/update records in tables. It seems that at the beginning of the project I used one and for some reason a few months ago switched to another.
Namely:
Working with record set objects -
Code:
With rs
.FindFirst "UserID = " & Forms!frm_Login.cba_UserName.Column(0)
.Edit
'etc etc
.Update
End With
and using SQL action queries
Code:
'*********
'Insert SQL
'*********
DoCmd.SetWarnings False
DoCmd.RunSQL ("INSERT INTO tbl_AdminError(AdminCode, AdminDescription)" & _
"VALUES (" & adminErrorCode & ",'" & adminErrDescrp & "');")
DoCmd.SetWarnings True
DoCmd.Close
'*********
'Update SQL
'*********
DoCmd.SetWarnings False
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.RunSQL ("UPDATE tbl_UserError SET tbl_UserError.ErrorFixed = -1, tbl_UserError.FixedBy = " & gblUserNumber & ", tbl_UserError.FixedTime = '" & Now() & _
"' WHERE tbl_UserError.[UserErrorID]= " & Me.lst_UserErrors.Column(0) & ";")
DoCmd.SetWarnings True
Now, I know there are many ways to accomplish the same thing, especially when programming, however I was wondering which you preferred to use in your VBA coding and why?
