Error 3464 (Data type mismatch in criteria expression) with OpenRecordset

DeathTrap82

Registered User.
Local time
Today, 05:24
Joined
Jun 25, 2012
Messages
10
I'm having some trouble with my code (posted below). It keeps throwing run-time error 3464 at me at the "Set rs = db.OpenRecordset(strSQL)" line. Any ideas?


Code:
Private Function concDegrees(r As DAO.Recordset, n As DAO.Recordset) As String
    Dim rID As Long, strDegrees As String, rs As DAO.Recordset, tempStr As String, strSQL As String
    
    rID = n!ID
    strDegrees = ""
    strSQL = "SELECT Degree FROM Degrees WHERE [Degrees].[ID] = " & rID & ""
    Set rs = CurrentDb.OpenRecordset(strSQL)
    
    rs.MoveFirst
    Do While Not rs.EOF
        tempStr = Trim(rs!Degree)
        strDegrees = strDegrees & ", " & tempStr
        rs.MoveNext
    Loop
    
    strDegrees = Right(strDegrees, Len(strDegrees) - 2)
    rs.Close
    Set rs = Nothing
    concDegrees = strDegrees
    
End Function
 
If the ID field is text it would need delimiters:

strSQL = "SELECT Degree FROM Degrees WHERE [Degrees].[ID] = '" & rID & "'"
 
If the ID field is text it would need delimiters:

strSQL = "SELECT Degree FROM Degrees WHERE [Degrees].[ID] = '" & rID & "'"

Alright, I've fixed that...but now it gives me an error saying "No current record." (Error 3021, if that is needed). There is definitely a table called Degrees with a column called Degree (I should probably rename them, that's going to drive me crazy).
 

Users who are viewing this thread

Back
Top Bottom