Capture Record Counts
I like elegant solutions to tough problems. In the program we were writing, we begin with millions of rows and after applying lots of edits, we are down to 30K rows.We wanted something to count the records to a table along the way so we could see what the effects of various edits did.
Public Function UpdateValTable(ValType As String, ProcTable As String)
Dim sqlString As String
Dim DB As Database
Dim Builder As Recordset
Dim SetUpdt As Recordset
Set DB = CurrentDb
On Error GoTo ErrHandleS
sqlString = "SELECT COUNT(*) as RecordCount FROM " & ProcTable
'Count records in Target Table
Set Builder = DB.OpenRecordset(sqlString, dbOpenDynaset)
Set SetUpdt = DB.OpenRecordset("tblValidation", dbOpenDynaset)
SetUpdt.AddNew
SetUpdt!Type = ValType
SetUpdt!Quantity = Builder.Fields("RecordCount")
SetUpdt!UserName = UserName()
SetUpdt.Update
Set Builder = Nothing
Set SetUpdt = Nothing
GoTo Exit_SomeName
Exit Function
Exit_SomeName:
Exit Function
ErrHandleS:
Select Case Err
Case 9999
Resume Next
Resume Exit_SomeName
Case Else
Call LogError(Err, Error$, "UpdateValTable()")
Resume Exit_SomeName
End Select
End Function
Call UpdateValTable TheNameofType, Table2PullFrom
In this case, we have a pre-built table called tblValidation with 4 columns; Type, Quantity, UserName, and Date. Date is set with default value of NOW().To access the function, I use Call UpdateValTable TheNameofType, Table2PullFrom within my code. I can use it anywhere to write a Validation record.
|