Reputation: 659
I am trying to check the values of a field in a recordset to see if they are all the same. The field is a string. However, there is no correct value the fields should have, they should simply all be equal to each other.
The idea is that when I call a function if all the fields (Company Name) in the recordset are not equal the function will exit.
Upvotes: 1
Views: 104
Reputation: 5386
You can use a simple count recordset based on company name
Something like this should work - modified for tablename and field name
You want to count number of DISTINCT companynames in your table (or query)
If they're all the same - then NumRecs returns 1 unique value
strSQL = "SELECT COUNT(*) AS NumRecs FROM " & _
"(SELECT DISTINCT Table1.CompanyName" & _
"FROM Table1) AS t1;"
Set rs = currentdb.openrecordset(strSQL)
if rs!NumRecs = 1 then
' all good
else
' exit function
endif
Upvotes: 2