I have a number of tables that I'd like to audit. The tables have numeric data, strings, and dates.
Before I call this function a copy of the data in all the fields is written to a temp table called TableAudit, the table I'm comparing with is TableSource.
I can't enumerate the names of these fields because they change depending on which table I am editing.
My problem is in the FOR loop below. I get and error saying that the method is not available for recAudit.fld.Va lue.
I don't know why.
Any help would be greatly appreciated.
Before I call this function a copy of the data in all the fields is written to a temp table called TableAudit, the table I'm comparing with is TableSource.
I can't enumerate the names of these fields because they change depending on which table I am editing.
My problem is in the FOR loop below. I get and error saying that the method is not available for recAudit.fld.Va lue.
I don't know why.
Any help would be greatly appreciated.
Code:
Function VerifierChamps(ByVal NomTableSource As String, ByVal NomTableAudit As String, sKeyField As String, lngKeyValue As Long)
On Error GoTo errhandler
Dim db As DAO.Database
Dim recTableSource As DAO.Recordset 'The table being audited
Dim recAudit As DAO.Recordset 'The temporary audit table
Dim fld As DAO.Field
Dim intCompare As Integer 'Supposed to be different than zero if matches are found
Dim blnCmp As Boolean
Set db = CurrentDb
Set recTableSource = db.OpenRecordset("SELECT * FROM " & NomTableSource & " WHERE " & sKeyField & " = " & lngKeyValue)
Set recAudit = db.OpenRecordset("SELECT * FROM " & NomTableAudit & " WHERE " & sKeyField & " = " & lngKeyValue)
intCompare = 0
blnCmp = False
'All the fields in the Source Table and in the Audit Table have exactly the same names
For Each fldS In recTableSource.Fields
If (fld.Value = recAudit.fld.Value) Then
intCompare = intCompare + 1
Else
intCompare = 0
End If
Next
If intCompare <> 0 Then
blnCmp = True
Else
blnCmp = False
End If
VerifierChamps = blnCmp
'If no errors
ExitHere:
Set fldA = Nothing
Set fldS = Nothing
Set tdf = Nothing
Set db = Nothing
Set recTableSource = Nothing
Set recAudit = Nothing
'Notify the user the process is complete.
'MsgBox "Record Print Complete"
Exit Function
errhandler:
'There is an error return as null
With Err
MsgBox "Error in VerfierChamps " & .Number & vbCrLf & .Description, _
vbOKOnly Or vbCritical, "GetFields"
End With
Resume ExitHere
End Function
Comment