Unfortunatley the table names have improper names with spaces in them but i have no controll over that
when i try to run this function in the immediate window I do not get the results I anticipate
The Table [Time Recording] has three entries which match the criteria passed
but im puzzled because not even the debug.print lines return anything at all
which kind suggests that i havent opend the record set properly
the sqlStr looks right but nothing about has records or No records in the output form the immediate window ???
here is the code
and here is the output from the immediate window

when i try to run this function in the immediate window I do not get the results I anticipate
The Table [Time Recording] has three entries which match the criteria passed
but im puzzled because not even the debug.print lines return anything at all

the sqlStr looks right but nothing about has records or No records in the output form the immediate window ???
here is the code
Code:
Public Function duplicates(caseref As String, Code As Integer)
Dim ret As Integer
Dim rs As DAO.Recordset
Dim db As Database
Dim strSQL As String
Dim TableName As String
Dim CodeFieldA As String
Dim CodeFieldB As String
Dim CaseField As String
TableName = "[Time Recording]"
CodeFieldA = "[Activity Code]"
CodeFieldB = "[Ineligible Code]"
CaseField = "[Case Ref No]"
strSQL = "SELECT " & CaseField & " FROM " & TableName & " WHERE " & CaseField & " = """ & caseref & """ And (" & CodeFieldA & " = " & Code & " OR " & CodeFieldB & " = " & Code & ")"
Debug.Print strSQL
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset, dbDenyWrite)
If (rs.RecordCount > 0) Then
Debug.Print "Has Records"
Else: Debug.Print "No Records"
End If
If rs.RecordCount <> 0 Then
rs.MoveFirst
While Not rs.EOF
Debug.Print "count"
rs.MoveNext
Wend
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Function
and here is the output from the immediate window
Code:
?Duplicates("19378WB",909)
SELECT [Case Ref No] FROM [Time Recording] WHERE [Case Ref No] = "19378WB" And ([Activity Code] = 909 OR [Ineligible Code] = 909)