I have to agree with ItsMe, a function call can be slow (and inefficient).
I have a query that takes about 2 hours to run - approx 5,000 records, with 4 calls to the function per record. Just a simple look up function using a record set.
BTW, "Type" is a reserved word in Access, so in my example, I changed it to "StressType".
Here are two functions to return a Boolean result. You didn't specify the table name and I changed a field name, soooooo:
Code:
Public Function HasStress(pStressType As String, pDivision As Integer) As Boolean
Dim r As DAO.Recordset
Dim sSQL As String
HasStress = False
sSQL = "SELECT tblStresses.StressType, tblStresses.Division"
sSQL = sSQL & " FROM tblStresses"
sSQL = sSQL & " WHERE tblStresses.StressType = '" & pStressType & "' AND tblStresses.Division = " & pDivision & ";"
Set r = CurrentDb.OpenRecordset(sSQL)
If Not (r.BOF And r.EOF) Then
HasStress = True
End If
r.Close
Set r = Nothing
End Function
Code:
Public Function HasStress2(pStressType As String, pDivision As Integer) As Boolean
Dim sSQL As String
HasStress2 = False
sSQL = "StressType = '" & pStressType & "' AND Division = " & pDivision
HasStress2 = DCount("*", "tblStresses", sSQL)
End Function
Allen Browne also has a DCount() replacement function, named ECount(), at http://allenbrowne.com/ser-66.html