I have to delete all records and re-import new ones on a fairly regular basis.
Then I have to update an empty field to a new value based on some other criteria.
I have code that looks like this to do it:
Code: Select all
Sub SetUp()
Debug.Print Now()
Dim rstPassed As DAO.Recordset
Dim dbPassed As DAO.Database
Set dbPassed = CurrentDb
Dim db As DAO.Database
Set db = CurrentDb
Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("select * from [tblSpend] where BU is null", dbOpenDynaset)
rst.MoveLast
Debug.Print rst.RecordCount
rst.MoveFirst
While Not rst.EOF
With rst
.Edit
!BU = GetNewBU(Nz(![Cost Ctr], ""), rstPassed, dbPassed, Nz(!Category, "x"))
.Update
End With
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
Set rstPassed = Nothing
Set dbPassed = Nothing
Set db = Nothing
Debug.Print Now()
MsgBox "Done!"
End Sub
Code: Select all
Function GetNewBU(strCC As String, rst As DAO.Recordset, db As DAO.Database, strCategoryIn As String) As String
'Dim db As DAO.Database
Set db = CurrentDb
'Dim rst As DAO.Recordset
Set rst = db.OpenRecordset("SELECT [TheField] FROM CostCenter WHERE CostCenter = '" & strCC & "'", dbOpenForwardOnly)
Dim strTemp As String
If rst.EOF And rst.BOF Then
strTemp = "OTHER"
Else
strTemp = rst![TheField]
End If
rst.Close
If strTemp = "OTHER" Then
Select Case strCategoryIn
Case "00055", "00059"
strTemp = "Network"
Case "00031", "00033"
strTemp = "Development"
Case Else
strTemp = "OTHER"
End Select
End If
GetNewBU = strTemp
End Function
Is there a way to NOT have it bloat?
Thanks!