DAO OpenRecordset and NULL results?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RobinDiederen
    New Member
    • Sep 2006
    • 19

    DAO OpenRecordset and NULL results?

    Using the code hereunder, I query my database (from MS Access VBA code). Some of my queries give empty results, which isn't like by my program.

    For example:
    Code:
    R5SQLC1 = "SELECT COUNT(*) FROM Planning AS D1, Planning AS D2 WHERE D1.werknemer=" & TheWorker & " AND D2.werknemer=" & TheWorker & " AND (D1.AanvangsTijd <= D1.Stoptijd) AND (DateDiff('d', D1, D2) = 1) AND (((D2.AanvangsTijd + 24) - D1.Stoptijd) < 44) AND D1.Datum < D2.Datum"
    Debug.Print R5SQLC1
    Set C1 = Db.OpenRecordset(R5SQLC1, dbOpenDynaset)
    This gives as an error:
    Run-time error '3601':
    Too few parameters, expected 2
    For as far as I can tell, this has to do with empty results. As these queries sometimes give empty results, I really need to do something about this. Thing is.. what, and how?

    Thanks in advance!
  • Nebojsa4
    New Member
    • Dec 2006
    • 6

    #2
    Originally posted by RobinDiederen
    Using the code hereunder, I query my database (from MS Access VBA code). Some of my queries give empty results, which isn't like by my program.

    For example:
    Code:
    R5SQLC1 = "SELECT COUNT(*) FROM Planning AS D1, Planning AS D2 WHERE D1.werknemer=" & TheWorker & " AND D2.werknemer=" & TheWorker & " AND (D1.AanvangsTijd <= D1.Stoptijd) AND (DateDiff('d', D1, D2) = 1) AND (((D2.AanvangsTijd + 24) - D1.Stoptijd) < 44) AND D1.Datum < D2.Datum"
    Debug.Print R5SQLC1
    Set C1 = Db.OpenRecordset(R5SQLC1, dbOpenDynaset)
    This gives as an error:

    For as far as I can tell, this has to do with empty results. As these queries sometimes give empty results, I really need to do something about this. Thing is.. what, and how?

    Thanks in advance!
    I think, You must the following syntax:

    Code:
    SELECT COUNT(Fieldname) FROM Planning AS [D1], Planning AS [D2] WHERE D1.werknemer=" & TheWorker & ", D2.werknemer=" & TheWorker & "... etc
    Try that.

    Comment

    • kowndinya
      New Member
      • Sep 2006
      • 26

      #3
      Originally posted by Nebojsa4
      I think, You must the following syntax:

      Code:
      SELECT COUNT(Fieldname) FROM Planning AS [D1], Planning AS [D2] WHERE D1.werknemer=" & TheWorker & ", D2.werknemer=" & TheWorker & "... etc
      Try that.

      Use the following:

      count the selected recordset.
      n= C1.recordcount
      if n>0 then
      .... do what you want
      else
      exit sub
      end if

      You will not see the error message.

      Good Luck.

      Comment

      • RobinDiederen
        New Member
        • Sep 2006
        • 19

        #4
        Thanks all. Doing it the dirty way (testing on the size of the recordset) is what does the trick..

        Thanks!

        Comment

        Working...