Hi all,
I am updating code in a database created by someone else, and I came across the use of a recordset that seems problematic. The author did not declare whether they wanted to use ADO or DAO, and there seemed to be a few other minor issues. I made a few small updates, but am uncertain whether my code is correct. Could someone review these code blocks and let me know if I did things correctly? Thanks!
Here is what I updated it to:
I am updating code in a database created by someone else, and I came across the use of a recordset that seems problematic. The author did not declare whether they wanted to use ADO or DAO, and there seemed to be a few other minor issues. I made a few small updates, but am uncertain whether my code is correct. Could someone review these code blocks and let me know if I did things correctly? Thanks!
Code:
Dim dbs As Database, rcd As Recordset
Set dbs = CurrentDb
Set rcd = dbs.OpenRecordset("tblClients")
rcd.AddNew
rcd("ClientID") = inClientID
rcd("ClientName") = inClientName
rcd("CAM") = inCAM
rcd("ClientStatusID") = inClientStatusID
rcd("BOBID") = inBOBID
rcd("RKSystemID") = inRKSystemID
rcd("Server") = inServer
If Not IsNull(inCallCenter) And inCallCenter <> "" Then rcd("CallCenter") = inCallCenter
If Not IsNull(inClosedDate) And inClosedDate <> "" Then rcd("ClosedDate") = inClosedDate
If Not IsNull(inMergedTo) And inMergedTo <> "" Then rcd("MergedTo") = inMergedTo
If Not IsNull(inSisterPlan) And inSisterPlan <> "" Then rcd("SisterPlan") = inSisterPlan
If Not IsNull(inClientComments) And inClientComments <> "" Then rcd("ClientComments") = inClientComments
If Not IsNull(inPlanLedgerNum) And inPlanLedgerNum <> "" Then rcd("PlanLedgerNum") = inPlanLedgerNum
If Not IsNull(inUCAcctName) And inUCAcctName <> "" Then rcd("UCAcctName") = inUCAcctName
If Not IsNull(UCAcctSSNPID) And inUCAcctSSNPID <> "" Then rcd("UCAcctSSNPID") = inUCAcctSSNPID
If Not IsNull(inUCMT) And inUCMT <> "" Then rcd("UCMT") = inUCMT
rcd.Update
rcd.Close
Here is what I updated it to:
Code:
Dim dbs As DAO.Database
Dim rcd As DAO.Recordset
Set dbs = CurrentDb
Set rcd = dbs.OpenRecordset("tblClients")
rcd.AddNew
rcd("ClientID") = inClientID
rcd("ClientName") = inClientName
rcd("CAM") = inCAM
rcd("ClientStatusID") = inClientStatusID
rcd("BOBID") = inBOBID
rcd("RKSystemID") = inRKSystemID
rcd("Server") = inServer
If Not IsNull(inCallCenter) And inCallCenter <> "" Then rcd("CallCenter") = inCallCenter
If Not IsNull(inClosedDate) And inClosedDate <> "" Then rcd("ClosedDate") = inClosedDate
If Not IsNull(inMergedTo) And inMergedTo <> "" Then rcd("MergedTo") = inMergedTo
If Not IsNull(inSisterPlan) And inSisterPlan <> "" Then rcd("SisterPlan") = inSisterPlan
If Not IsNull(inClientComments) And inClientComments <> "" Then rcd("ClientComments") = inClientComments
If Not IsNull(inPlanLedgerNum) And inPlanLedgerNum <> "" Then rcd("PlanLedgerNum") = inPlanLedgerNum
If Not IsNull(inUCAcctName) And inUCAcctName <> "" Then rcd("UCAcctName") = inUCAcctName
If Not IsNull(UCAcctSSNPID) And inUCAcctSSNPID <> "" Then rcd("UCAcctSSNPID") = inUCAcctSSNPID
If Not IsNull(inUCMT) And inUCMT <> "" Then rcd("UCMT") = inUCMT
rcd.Update
rcd.Close
Set rcd = Nothing
Set dbs = Nothing<strike></strike>