Dim Rs As DAO.Recordset
Set Rs = CurrentDb.Openrecordset("TblCompanies")
With Rs
.AddNew
!CompanyName = NewData
!CompanyLogDate = Date()
!CompanyLogTime = Now()
!CompanyDateLastChanged = Date()
.Update
.Close
End With
Set Rs = Nothing
Of course if you are adding multiple records, the recordset is kept open for the session rather than opening and closing each time.
The operator is really better thought of less as a separator and more as part of the second half of the term. Strictly speaking a bang(!) indicates the following term is an object while the dot(.) indicates a Property or Method.
Posters sometimes ask of it should be Me. or Me! when in fact they should ask if it is .fieldname or !fieldname. No expression ends in an operator so definitely no to:
Set Rs. = Nothing
Bob Larson wrote on another thread from 2007 that it's a good isea to make RS = Nothing to empty the varible from memory space. Should that apply to all varibles?
Consensus(?) seems to be that the object variable is cleared out by garbage collection when the sub or function closes so it is not strictly necessary. (Duck for cover?)