| re: Comparing Text Fields in table
Perhaps this (air):
Private Const cTableWithFieldsToCompare As String = "MyTable"
Private Const cFirstField As String = "txtMonthOld"
Private Const cSecondField As String = "txtMonthCurrent"
Function CompareMe() as Boolean
Dim db As DAO.Database
Dim rec as DAO.Recordset
Dim return as Boolean
'Set Default Return Value to False
return = False
Set db = CurrentDb()
With db
'Open a dynaset (so findfirst method is available)
Set rec = .OpenRecordSet(cTableWithFieldsToCompare, dbOpenDynaset)
With rec
'Populate recordset
.MoveLast
.MoveFirst
'Insert Code here to find the record??
'Example:
'.FindFirst("ID = " & somevariable)
'Here's the logic to compare the fields
If .Fields(cFirstField) = .Fields(cSecondField) Then
return = True
End If
.Close
End With
.Close
End With
'Clean up
Set rec = Nothing
Set db = Nothing
'Set return value
CompareMe = return
End Function
This function returns true if the fields match, false if they don't.
Note that I've only stubbed out code to find a particular record. I
would envision a parameter to the function (i.e. see somevariable
above) that provides the key to the record you need.
HTH,
Johnny
(feel free to email me for clarification at j{deleteme]meredith AT g
MAil DOT com) |