I am trying to use a query with a form reference in DAO, but it does not return any records. Here is my code:
I have a suspicion it might be because I am trying to use the Year function.
Also, when I run the query with the same parameters in Access I get exactly what I need.
Code:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs1 As DAO.Recordset
Set db = CurrentDb()
Set qdf = db.QueryDefs("qry_Species_by_park_by_year")
qdf.Parameters(0) = Forms!Occu_formatting!Park
qdf.Parameters(1) = Year(Forms!Occu_formatting!survey_begin_date)
qdf.Parameters(2) = Forms!Occu_formatting!obs_inits
Set rs1 = qdf.OpenRecordset
If rs1.RecordCount = 0 Then
MsgBox ("No records in query")
Exit Sub
End If
Also, when I run the query with the same parameters in Access I get exactly what I need.
Comment