By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,580 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

Using a query with a form reference in DAO

P: 16
I am trying to use a query with a form reference in DAO, but it does not return any records. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim qdf As DAO.QueryDef
  3. Dim rs1 As DAO.Recordset
  5.     Set db = CurrentDb()
  6.     Set qdf = db.QueryDefs("qry_Species_by_park_by_year")
  7.     qdf.Parameters(0) = Forms!Occu_formatting!Park
  8.     qdf.Parameters(1) = Year(Forms!Occu_formatting!survey_begin_date)
  9.     qdf.Parameters(2) = Forms!Occu_formatting!obs_inits
  10.     Set rs1 = qdf.OpenRecordset
  12.     If rs1.RecordCount = 0 Then
  13.         MsgBox ("No records in query")
  14.         Exit Sub
  15.     End If
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.
Mar 24 '14 #1
Share this Question
Share on Google+
1 Reply

P: 16
I solved my own problem!

The answer is that the Year function was causing the problem. To get around this issue, I created an invisible unbound text box in the form that got the year from the date field. Everything else stayed the same except removing the year function from the qdf.paramters(1) line and reassigning it to my new invisible text box.
Mar 24 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.